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

Side by Side Diff: vm/object.h

Issue 10782016: Enforce length/size limits for variable size heap object in order to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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"
11 #include "vm/bitmap.h" 11 #include "vm/bitmap.h"
12 #include "vm/dart.h" 12 #include "vm/dart.h"
13 #include "vm/globals.h" 13 #include "vm/globals.h"
14 #include "vm/handles.h" 14 #include "vm/handles.h"
15 #include "vm/heap.h" 15 #include "vm/heap.h"
16 #include "vm/isolate.h" 16 #include "vm/isolate.h"
17 #include "vm/os.h" 17 #include "vm/os.h"
18 #include "vm/raw_object.h" 18 #include "vm/raw_object.h"
19 #include "vm/scanner.h" 19 #include "vm/scanner.h"
20 20
21 namespace dart { 21 namespace dart {
22 22
23 #define MAX_ELEMENTS(type) \
24 ((kIntptrMax - sizeof(Raw##type) - sizeof(RawObject)) / \
cshapiro 2012/07/17 22:54:30 Give consideration to the maximum value of a Smi.
turnidge 2012/07/18 18:17:04 This is awkward to do, since the Smi::MaxValue isn
cshapiro 2012/07/19 05:49:01 I lost an earlier comment. It may appear after I
turnidge 2012/07/31 23:21:45 Done.
25 type::kBytesPerElement)
26
23 // Forward declarations. 27 // Forward declarations.
24 #define DEFINE_FORWARD_DECLARATION(clazz) \ 28 #define DEFINE_FORWARD_DECLARATION(clazz) \
25 class clazz; 29 class clazz;
26 CLASS_LIST(DEFINE_FORWARD_DECLARATION) 30 CLASS_LIST(DEFINE_FORWARD_DECLARATION)
27 #undef DEFINE_FORWARD_DECLARATION 31 #undef DEFINE_FORWARD_DECLARATION
28 class Api; 32 class Api;
29 class Assembler; 33 class Assembler;
30 class Code; 34 class Code;
31 class LocalScope; 35 class LocalScope;
32 36
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const; 1197 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const;
1194 virtual bool IsResolved() const; 1198 virtual bool IsResolved() const;
1195 virtual bool IsInstantiated() const; 1199 virtual bool IsInstantiated() const;
1196 virtual bool IsUninstantiatedIdentity() const; 1200 virtual bool IsUninstantiatedIdentity() const;
1197 // Canonicalize only if instantiated, otherwise returns 'this'. 1201 // Canonicalize only if instantiated, otherwise returns 'this'.
1198 virtual RawAbstractTypeArguments* Canonicalize() const; 1202 virtual RawAbstractTypeArguments* Canonicalize() const;
1199 1203
1200 virtual RawAbstractTypeArguments* InstantiateFrom( 1204 virtual RawAbstractTypeArguments* InstantiateFrom(
1201 const AbstractTypeArguments& instantiator_type_arguments) const; 1205 const AbstractTypeArguments& instantiator_type_arguments) const;
1202 1206
1207 static const intptr_t kBytesPerElement = kWordSize;
1208 static const intptr_t kMaxElements = MAX_ELEMENTS(TypeArguments);
1209
1203 static intptr_t length_offset() { 1210 static intptr_t length_offset() {
1204 return OFFSET_OF(RawTypeArguments, length_); 1211 return OFFSET_OF(RawTypeArguments, length_);
1205 } 1212 }
1206 1213
1207 static intptr_t InstanceSize() { 1214 static intptr_t InstanceSize() {
1208 ASSERT(sizeof(RawTypeArguments) == OFFSET_OF(RawTypeArguments, types_)); 1215 ASSERT(sizeof(RawTypeArguments) == OFFSET_OF(RawTypeArguments, types_));
1209 return 0; 1216 return 0;
1210 } 1217 }
1211 1218
1212 static intptr_t InstanceSize(intptr_t len) { 1219 static intptr_t InstanceSize(intptr_t len) {
1213 // Ensure that the types_ is not adding to the object length. 1220 // Ensure that the types_ is not adding to the object length.
1214 ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (1 * kWordSize))); 1221 ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (1 * kWordSize)));
1215 return RoundedAllocationSize(sizeof(RawTypeArguments) + (len * kWordSize)); 1222 ASSERT(0 <= len && len <= kMaxElements);
1223 return RoundedAllocationSize(
1224 sizeof(RawTypeArguments) + (len * kBytesPerElement));
1216 } 1225 }
1217 1226
1218 static RawTypeArguments* New(intptr_t len, Heap::Space space = Heap::kOld); 1227 static RawTypeArguments* New(intptr_t len, Heap::Space space = Heap::kOld);
1219 1228
1220 private: 1229 private:
1221 // Make sure that the array size cannot wrap around.
1222 static const intptr_t kMaxTypes = 512 * 1024 * 1024;
1223 RawAbstractType** TypeAddr(intptr_t index) const; 1230 RawAbstractType** TypeAddr(intptr_t index) const;
1224 void SetLength(intptr_t value) const; 1231 void SetLength(intptr_t value) const;
1225 1232
1226 HEAP_OBJECT_IMPLEMENTATION(TypeArguments, AbstractTypeArguments); 1233 HEAP_OBJECT_IMPLEMENTATION(TypeArguments, AbstractTypeArguments);
1227 friend class Class; 1234 friend class Class;
1228 }; 1235 };
1229 1236
1230 1237
1231 // An instance of InstantiatedTypeArguments is never encountered at compile 1238 // An instance of InstantiatedTypeArguments is never encountered at compile
1232 // time, but only at run time, when type parameters can be matched to actual 1239 // time, but only at run time, when type parameters can be matched to actual
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 public: 1707 public:
1701 inline intptr_t Length() const; 1708 inline intptr_t Length() const;
1702 1709
1703 RawArray* TokenObjects() const; 1710 RawArray* TokenObjects() const;
1704 void SetTokenObjects(const Array& value) const; 1711 void SetTokenObjects(const Array& value) const;
1705 1712
1706 RawString* GenerateSource() const; 1713 RawString* GenerateSource() const;
1707 intptr_t ComputeSourcePosition(intptr_t tok_pos) const; 1714 intptr_t ComputeSourcePosition(intptr_t tok_pos) const;
1708 intptr_t ComputeTokenPosition(intptr_t src_pos) const; 1715 intptr_t ComputeTokenPosition(intptr_t src_pos) const;
1709 1716
1717 static const intptr_t kBytesPerElement = 1;
1718 static const intptr_t kMaxElements = MAX_ELEMENTS(TokenStream);
1719
1710 static intptr_t InstanceSize() { 1720 static intptr_t InstanceSize() {
1711 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_)); 1721 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_));
1712 return 0; 1722 return 0;
1713 } 1723 }
1714 static intptr_t InstanceSize(intptr_t len) { 1724 static intptr_t InstanceSize(intptr_t len) {
1715 return RoundedAllocationSize(sizeof(RawTokenStream) + len); 1725 ASSERT(0 <= len && len <= kMaxElements);
1726 return RoundedAllocationSize(
1727 sizeof(RawTokenStream) + (len * kBytesPerElement));
1716 } 1728 }
1717 1729
1718 static RawTokenStream* New(intptr_t length); 1730 static RawTokenStream* New(intptr_t length);
1719 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens); 1731 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens);
1720 1732
1721 // The class Iterator encapsulates iteration over the tokens 1733 // The class Iterator encapsulates iteration over the tokens
1722 // in a TokenStream object. 1734 // in a TokenStream object.
1723 class Iterator : ValueObject { 1735 class Iterator : ValueObject {
1724 public: 1736 public:
1725 Iterator(const TokenStream& tokens, intptr_t token_pos); 1737 Iterator(const TokenStream& tokens, intptr_t token_pos);
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
2040 2052
2041 class Instructions : public Object { 2053 class Instructions : public Object {
2042 public: 2054 public:
2043 intptr_t size() const { return raw_ptr()->size_; } 2055 intptr_t size() const { return raw_ptr()->size_; }
2044 RawCode* code() const { return raw_ptr()->code_; } 2056 RawCode* code() const { return raw_ptr()->code_; }
2045 2057
2046 uword EntryPoint() const { 2058 uword EntryPoint() const {
2047 return reinterpret_cast<uword>(raw_ptr()) + HeaderSize(); 2059 return reinterpret_cast<uword>(raw_ptr()) + HeaderSize();
2048 } 2060 }
2049 2061
2062 static const intptr_t kMaxElements = (kIntptrMax -
2063 (sizeof(RawInstructions) +
2064 sizeof(RawObject) +
2065 (2 * OS::kMaxPreferredCodeAlignment)));
2066
2050 static intptr_t InstanceSize() { 2067 static intptr_t InstanceSize() {
2051 ASSERT(sizeof(RawInstructions) == OFFSET_OF(RawInstructions, data_)); 2068 ASSERT(sizeof(RawInstructions) == OFFSET_OF(RawInstructions, data_));
2052 return 0; 2069 return 0;
2053 } 2070 }
2054 2071
2055 static intptr_t InstanceSize(intptr_t size) { 2072 static intptr_t InstanceSize(intptr_t size) {
2056 intptr_t instructions_size = Utils::RoundUp(size, 2073 intptr_t instructions_size = Utils::RoundUp(size,
2057 OS::PreferredCodeAlignment()); 2074 OS::PreferredCodeAlignment());
2058 intptr_t result = instructions_size + HeaderSize(); 2075 intptr_t result = instructions_size + HeaderSize();
2059 ASSERT(result % OS::PreferredCodeAlignment() == 0); 2076 ASSERT(result % OS::PreferredCodeAlignment() == 0);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2095 intptr_t Length() const; 2112 intptr_t Length() const;
2096 2113
2097 RawString* GetName(intptr_t var_index) const; 2114 RawString* GetName(intptr_t var_index) const;
2098 2115
2099 void SetVar(intptr_t var_index, 2116 void SetVar(intptr_t var_index,
2100 const String& name, 2117 const String& name,
2101 RawLocalVarDescriptors::VarInfo* info) const; 2118 RawLocalVarDescriptors::VarInfo* info) const;
2102 2119
2103 void GetInfo(intptr_t var_index, RawLocalVarDescriptors::VarInfo* info) const; 2120 void GetInfo(intptr_t var_index, RawLocalVarDescriptors::VarInfo* info) const;
2104 2121
2122 static const intptr_t kBytesPerElement =
2123 sizeof(RawLocalVarDescriptors::VarInfo);
2124 static const intptr_t kMaxElements = MAX_ELEMENTS(LocalVarDescriptors);
2125
2105 static intptr_t InstanceSize() { 2126 static intptr_t InstanceSize() {
2106 ASSERT(sizeof(RawLocalVarDescriptors) == 2127 ASSERT(sizeof(RawLocalVarDescriptors) ==
2107 OFFSET_OF(RawLocalVarDescriptors, data_)); 2128 OFFSET_OF(RawLocalVarDescriptors, data_));
2108 return 0; 2129 return 0;
2109 } 2130 }
2110 static intptr_t InstanceSize(intptr_t len) { 2131 static intptr_t InstanceSize(intptr_t len) {
2132 ASSERT(0 <= len && len <= kMaxElements);
2111 return RoundedAllocationSize( 2133 return RoundedAllocationSize(
2112 sizeof(RawLocalVarDescriptors) + 2134 sizeof(RawLocalVarDescriptors) + (len * kBytesPerElement));
2113 (len * sizeof(RawLocalVarDescriptors::VarInfo)));
2114 } 2135 }
2115 2136
2116 static RawLocalVarDescriptors* New(intptr_t num_variables); 2137 static RawLocalVarDescriptors* New(intptr_t num_variables);
2117 2138
2118 private: 2139 private:
2119 HEAP_OBJECT_IMPLEMENTATION(LocalVarDescriptors, Object); 2140 HEAP_OBJECT_IMPLEMENTATION(LocalVarDescriptors, Object);
2120 friend class Class; 2141 friend class Class;
2121 }; 2142 };
2122 2143
2123 2144
2124 class PcDescriptors : public Object { 2145 class PcDescriptors : public Object {
2146 private:
2147 // Describes the layout of PC descriptor data.
2148 enum {
2149 kPcEntry = 0, // PC value of the descriptor, unique.
2150 kKindEntry,
2151 kNodeIdEntry, // AST node id.
2152 kTokenIndexEntry, // Token position in source of PC.
2153 kTryIndexEntry, // Try block index of PC.
2154 // We would potentially be adding other objects here like
2155 // pointer maps for optimized functions, local variables information etc.
2156 kNumberOfEntries
2157 };
2158
2125 public: 2159 public:
2126 enum Kind { 2160 enum Kind {
2127 kDeopt = 0, // Deoptimization cotinuation point. 2161 kDeopt = 0, // Deoptimization cotinuation point.
2128 kPatchCode, // Buffer for patching code entry. 2162 kPatchCode, // Buffer for patching code entry.
2129 kIcCall, // IC call. 2163 kIcCall, // IC call.
2130 kFuncCall, // Call to known target, e.g. static call, closure call. 2164 kFuncCall, // Call to known target, e.g. static call, closure call.
2131 kReturn, // Return from function. 2165 kReturn, // Return from function.
2132 kOther 2166 kOther
2133 }; 2167 };
2134 2168
(...skipping 12 matching lines...) Expand all
2147 intptr_t node_id, 2181 intptr_t node_id,
2148 intptr_t token_pos, 2182 intptr_t token_pos,
2149 intptr_t try_index) const { 2183 intptr_t try_index) const {
2150 SetPC(index, pc); 2184 SetPC(index, pc);
2151 SetKind(index, kind); 2185 SetKind(index, kind);
2152 SetNodeId(index, node_id); 2186 SetNodeId(index, node_id);
2153 SetTokenIndex(index, token_pos); 2187 SetTokenIndex(index, token_pos);
2154 SetTryIndex(index, try_index); 2188 SetTryIndex(index, try_index);
2155 } 2189 }
2156 2190
2191 static const intptr_t kBytesPerElement = (kNumberOfEntries * kWordSize);
2192 static const intptr_t kMaxElements = MAX_ELEMENTS(PcDescriptors);
2193
2157 static intptr_t InstanceSize() { 2194 static intptr_t InstanceSize() {
2158 ASSERT(sizeof(RawPcDescriptors) == OFFSET_OF(RawPcDescriptors, data_)); 2195 ASSERT(sizeof(RawPcDescriptors) == OFFSET_OF(RawPcDescriptors, data_));
2159 return 0; 2196 return 0;
2160 } 2197 }
2161 static intptr_t InstanceSize(intptr_t len) { 2198 static intptr_t InstanceSize(intptr_t len) {
2199 ASSERT(0 <= len && len <= kMaxElements);
2162 return RoundedAllocationSize( 2200 return RoundedAllocationSize(
2163 sizeof(RawPcDescriptors) + (len * kNumberOfEntries * kWordSize)); 2201 sizeof(RawPcDescriptors) + (len * kBytesPerElement));
2164 } 2202 }
2165 2203
2166 static RawPcDescriptors* New(intptr_t num_descriptors); 2204 static RawPcDescriptors* New(intptr_t num_descriptors);
2167 2205
2168 // Verify (assert) assumptions about pc descriptors in debug mode. 2206 // Verify (assert) assumptions about pc descriptors in debug mode.
2169 void Verify(bool check_ids) const; 2207 void Verify(bool check_ids) const;
2170 2208
2171 // We would have a VisitPointers function here to traverse the 2209 // We would have a VisitPointers function here to traverse the
2172 // pc descriptors table to visit objects if any in the table. 2210 // pc descriptors table to visit objects if any in the table.
2173 2211
2174 private: 2212 private:
2175 // Describes the layout of PC descriptor data.
2176 enum {
2177 kPcEntry = 0, // PC value of the descriptor, unique.
2178 kKindEntry,
2179 kNodeIdEntry, // AST node id.
2180 kTokenIndexEntry, // Token position in source of PC.
2181 kTryIndexEntry, // Try block index of PC.
2182 // We would potentially be adding other objects here like
2183 // pointer maps for optimized functions, local variables information etc.
2184 kNumberOfEntries
2185 };
2186
2187 void SetPC(intptr_t index, uword value) const; 2213 void SetPC(intptr_t index, uword value) const;
2188 void SetKind(intptr_t index, PcDescriptors::Kind kind) const; 2214 void SetKind(intptr_t index, PcDescriptors::Kind kind) const;
2189 void SetNodeId(intptr_t index, intptr_t value) const; 2215 void SetNodeId(intptr_t index, intptr_t value) const;
2190 void SetTokenIndex(intptr_t index, intptr_t value) const; 2216 void SetTokenIndex(intptr_t index, intptr_t value) const;
2191 void SetTryIndex(intptr_t index, intptr_t value) const; 2217 void SetTryIndex(intptr_t index, intptr_t value) const;
2192 2218
2193 void SetLength(intptr_t value) const; 2219 void SetLength(intptr_t value) const;
2194 2220
2195 intptr_t* EntryAddr(intptr_t index, intptr_t entry_offset) const { 2221 intptr_t* EntryAddr(intptr_t index, intptr_t entry_offset) const {
2196 ASSERT((index >=0) && (index < Length())); 2222 ASSERT((index >=0) && (index < Length()));
(...skipping 22 matching lines...) Expand all
2219 2245
2220 RawCode* GetCode() const { return raw_ptr()->code_; } 2246 RawCode* GetCode() const { return raw_ptr()->code_; }
2221 void SetCode(const Code& code) const; 2247 void SetCode(const Code& code) const;
2222 2248
2223 // Return the offset of the highest stack slot that has an object. 2249 // Return the offset of the highest stack slot that has an object.
2224 intptr_t MaximumBitOffset() const { return raw_ptr()->max_set_bit_offset_; } 2250 intptr_t MaximumBitOffset() const { return raw_ptr()->max_set_bit_offset_; }
2225 2251
2226 // Return the offset of the lowest stack slot that has an object. 2252 // Return the offset of the lowest stack slot that has an object.
2227 intptr_t MinimumBitOffset() const { return raw_ptr()->min_set_bit_offset_; } 2253 intptr_t MinimumBitOffset() const { return raw_ptr()->min_set_bit_offset_; }
2228 2254
2255 static const intptr_t kBytesPerElement = kWordSize;
2256 static const intptr_t kMaxElements = MAX_ELEMENTS(Stackmap);
2257
2229 static intptr_t InstanceSize() { 2258 static intptr_t InstanceSize() {
2230 ASSERT(sizeof(RawStackmap) == OFFSET_OF(RawStackmap, data_)); 2259 ASSERT(sizeof(RawStackmap) == OFFSET_OF(RawStackmap, data_));
2231 return 0; 2260 return 0;
2232 } 2261 }
2233 static intptr_t InstanceSize(intptr_t size) { 2262 static intptr_t InstanceSize(intptr_t len) {
2234 return RoundedAllocationSize(sizeof(RawStackmap) + (size * kWordSize)); 2263 ASSERT(0 <= len && len <= kMaxElements);
2264 return RoundedAllocationSize(
2265 sizeof(RawStackmap) + (len * kBytesPerElement));
2235 } 2266 }
2236 static RawStackmap* New(uword pc, BitmapBuilder* bmap); 2267 static RawStackmap* New(uword pc, BitmapBuilder* bmap);
2237 2268
2238 private: 2269 private:
2239 inline intptr_t SizeInBits() const; 2270 inline intptr_t SizeInBits() const;
2240 2271
2241 void SetMinBitOffset(intptr_t value) const { 2272 void SetMinBitOffset(intptr_t value) const {
2242 raw_ptr()->min_set_bit_offset_ = value; 2273 raw_ptr()->min_set_bit_offset_ = value;
2243 } 2274 }
2244 void SetMaxBitOffset(intptr_t value) const { 2275 void SetMaxBitOffset(intptr_t value) const {
2245 raw_ptr()->max_set_bit_offset_ = value; 2276 raw_ptr()->max_set_bit_offset_ = value;
2246 } 2277 }
2247 2278
2248 bool InRange(intptr_t offset) const { return offset < SizeInBits(); } 2279 bool InRange(intptr_t offset) const { return offset < SizeInBits(); }
2249 2280
2250 bool GetBit(intptr_t bit_offset) const; 2281 bool GetBit(intptr_t bit_offset) const;
2251 void SetBit(intptr_t bit_offset, bool value) const; 2282 void SetBit(intptr_t bit_offset, bool value) const;
2252 2283
2253 void set_bitmap_size_in_bytes(intptr_t value) const; 2284 void set_bitmap_size_in_bytes(intptr_t value) const;
2254 2285
2255 HEAP_OBJECT_IMPLEMENTATION(Stackmap, Object); 2286 HEAP_OBJECT_IMPLEMENTATION(Stackmap, Object);
2256 friend class Class; 2287 friend class Class;
2257 friend class BitmapBuilder; 2288 friend class BitmapBuilder;
2258 }; 2289 };
2259 2290
2260 2291
2261 class ExceptionHandlers : public Object { 2292 class ExceptionHandlers : public Object {
2293 private:
2294 // Describes the layout of exception handler data.
2295 enum {
2296 kTryIndexEntry = 0, // Try block index associated with handler.
2297 kHandlerPcEntry, // PC value of handler.
2298 kNumberOfEntries
2299 };
2300
2262 public: 2301 public:
2263 intptr_t Length() const; 2302 intptr_t Length() const;
2264 2303
2265 intptr_t TryIndex(intptr_t index) const; 2304 intptr_t TryIndex(intptr_t index) const;
2266 intptr_t HandlerPC(intptr_t index) const; 2305 intptr_t HandlerPC(intptr_t index) const;
2267 2306
2268 void SetHandlerEntry(intptr_t index, 2307 void SetHandlerEntry(intptr_t index,
2269 intptr_t try_index, 2308 intptr_t try_index,
2270 intptr_t handler_pc) const { 2309 intptr_t handler_pc) const {
2271 SetTryIndex(index, try_index); 2310 SetTryIndex(index, try_index);
2272 SetHandlerPC(index, handler_pc); 2311 SetHandlerPC(index, handler_pc);
2273 } 2312 }
2274 2313
2314 static const intptr_t kBytesPerElement = (kNumberOfEntries * kWordSize);
2315 static const intptr_t kMaxElements = MAX_ELEMENTS(ExceptionHandlers);
2316
2275 static intptr_t InstanceSize() { 2317 static intptr_t InstanceSize() {
2276 ASSERT(sizeof(RawExceptionHandlers) == OFFSET_OF(RawExceptionHandlers, 2318 ASSERT(sizeof(RawExceptionHandlers) == OFFSET_OF(RawExceptionHandlers,
2277 data_)); 2319 data_));
2278 return 0; 2320 return 0;
2279 } 2321 }
2280 static intptr_t InstanceSize(intptr_t len) { 2322 static intptr_t InstanceSize(intptr_t len) {
2281 return RoundedAllocationSize(sizeof(RawExceptionHandlers) + 2323 ASSERT(0 <= len && len <= kMaxElements);
2282 (len * kNumberOfEntries * kWordSize)); 2324 return RoundedAllocationSize(
2325 sizeof(RawExceptionHandlers) + (len * kBytesPerElement));
2283 } 2326 }
2284 2327
2285 static RawExceptionHandlers* New(intptr_t num_handlers); 2328 static RawExceptionHandlers* New(intptr_t num_handlers);
2286 2329
2287 // We would have a VisitPointers function here to traverse the 2330 // We would have a VisitPointers function here to traverse the
2288 // exception handler table to visit objects if any in the table. 2331 // exception handler table to visit objects if any in the table.
2289 2332
2290 private: 2333 private:
2291 // Describes the layout of exception handler data.
2292 enum {
2293 kTryIndexEntry = 0, // Try block index associated with handler.
2294 kHandlerPcEntry, // PC value of handler.
2295 kNumberOfEntries
2296 };
2297
2298 void SetTryIndex(intptr_t index, intptr_t value) const; 2334 void SetTryIndex(intptr_t index, intptr_t value) const;
2299 void SetHandlerPC(intptr_t index, intptr_t value) const; 2335 void SetHandlerPC(intptr_t index, intptr_t value) const;
2300 2336
2301 void SetLength(intptr_t value) const; 2337 void SetLength(intptr_t value) const;
2302 2338
2303 intptr_t* EntryAddr(intptr_t index, intptr_t entry_offset) const { 2339 intptr_t* EntryAddr(intptr_t index, intptr_t entry_offset) const {
2304 ASSERT((index >=0) && (index < Length())); 2340 ASSERT((index >=0) && (index < Length()));
2305 intptr_t data_index = (index * kNumberOfEntries) + entry_offset; 2341 intptr_t data_index = (index * kNumberOfEntries) + entry_offset;
2306 return &raw_ptr()->data_[data_index]; 2342 return &raw_ptr()->data_[data_index];
2307 } 2343 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2398 RawFunction* function() const { 2434 RawFunction* function() const {
2399 return raw_ptr()->function_; 2435 return raw_ptr()->function_;
2400 } 2436 }
2401 void set_function(const Function& function) const { 2437 void set_function(const Function& function) const {
2402 StorePointer(&raw_ptr()->function_, function.raw()); 2438 StorePointer(&raw_ptr()->function_, function.raw());
2403 } 2439 }
2404 2440
2405 // We would have a VisitPointers function here to traverse all the 2441 // We would have a VisitPointers function here to traverse all the
2406 // embedded objects in the instructions using pointer_offsets. 2442 // embedded objects in the instructions using pointer_offsets.
2407 2443
2444 static const intptr_t kBytesPerElement =
2445 sizeof(reinterpret_cast<RawCode*>(0)->data_[0]);
2446 static const intptr_t kMaxElements = MAX_ELEMENTS(Code);
2447
2408 static intptr_t InstanceSize() { 2448 static intptr_t InstanceSize() {
2409 ASSERT(sizeof(RawCode) == OFFSET_OF(RawCode, data_)); 2449 ASSERT(sizeof(RawCode) == OFFSET_OF(RawCode, data_));
2410 return 0; 2450 return 0;
2411 } 2451 }
2412 static intptr_t InstanceSize(intptr_t pointer_offsets_length) { 2452 static intptr_t InstanceSize(intptr_t len) {
2413 return RoundedAllocationSize( 2453 ASSERT(0 <= len && len <= kMaxElements);
2414 sizeof(RawCode) + (pointer_offsets_length * kEntrySize)); 2454 return RoundedAllocationSize(sizeof(RawCode) + (len * kBytesPerElement));
2415 } 2455 }
2416 static RawCode* FinalizeCode(const Function& function, Assembler* assembler); 2456 static RawCode* FinalizeCode(const Function& function, Assembler* assembler);
2417 static RawCode* FinalizeCode(const char* name, Assembler* assembler); 2457 static RawCode* FinalizeCode(const char* name, Assembler* assembler);
2418 static RawCode* LookupCode(uword pc); 2458 static RawCode* LookupCode(uword pc);
2419 2459
2420 int32_t GetPointerOffsetAt(int index) const { 2460 int32_t GetPointerOffsetAt(int index) const {
2421 return *PointerOffsetAddrAt(index); 2461 return *PointerOffsetAddrAt(index);
2422 } 2462 }
2423 intptr_t GetTokenIndexOfPC(uword pc) const; 2463 intptr_t GetTokenIndexOfPC(uword pc) const;
2424 2464
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2471 return &raw_ptr()->data_[index]; 2511 return &raw_ptr()->data_[index];
2472 } 2512 }
2473 void SetPointerOffsetAt(int index, int32_t offset_in_instructions) { 2513 void SetPointerOffsetAt(int index, int32_t offset_in_instructions) {
2474 *PointerOffsetAddrAt(index) = offset_in_instructions; 2514 *PointerOffsetAddrAt(index) = offset_in_instructions;
2475 } 2515 }
2476 2516
2477 // New is a private method as RawInstruction and RawCode objects should 2517 // New is a private method as RawInstruction and RawCode objects should
2478 // only be created using the Code::FinalizeCode method. This method creates 2518 // only be created using the Code::FinalizeCode method. This method creates
2479 // the RawInstruction and RawCode objects, sets up the pointer offsets 2519 // the RawInstruction and RawCode objects, sets up the pointer offsets
2480 // and links the two in a GC safe manner. 2520 // and links the two in a GC safe manner.
2481 static RawCode* New(int pointer_offsets_length); 2521 static RawCode* New(intptr_t pointer_offsets_length);
2482 2522
2483 HEAP_OBJECT_IMPLEMENTATION(Code, Object); 2523 HEAP_OBJECT_IMPLEMENTATION(Code, Object);
2484 friend class Class; 2524 friend class Class;
2485 }; 2525 };
2486 2526
2487 2527
2488 class Context : public Object { 2528 class Context : public Object {
2489 public: 2529 public:
2490 RawContext* parent() const { return raw_ptr()->parent_; } 2530 RawContext* parent() const { return raw_ptr()->parent_; }
2491 void set_parent(const Context& parent) const { 2531 void set_parent(const Context& parent) const {
2492 ASSERT(parent.IsNull() || parent.isolate() == Isolate::Current()); 2532 ASSERT(parent.IsNull() || parent.isolate() == Isolate::Current());
2493 StorePointer(&raw_ptr()->parent_, parent.raw()); 2533 StorePointer(&raw_ptr()->parent_, parent.raw());
2494 } 2534 }
2495 static intptr_t parent_offset() { return OFFSET_OF(RawContext, parent_); } 2535 static intptr_t parent_offset() { return OFFSET_OF(RawContext, parent_); }
2496 2536
2497 Isolate* isolate() const { return raw_ptr()->isolate_; } 2537 Isolate* isolate() const { return raw_ptr()->isolate_; }
2498 static intptr_t isolate_offset() { return OFFSET_OF(RawContext, isolate_); } 2538 static intptr_t isolate_offset() { return OFFSET_OF(RawContext, isolate_); }
2499 2539
2500 intptr_t num_variables() const { return raw_ptr()->num_variables_; } 2540 intptr_t num_variables() const { return raw_ptr()->num_variables_; }
2501 static intptr_t num_variables_offset() { 2541 static intptr_t num_variables_offset() {
2502 return OFFSET_OF(RawContext, num_variables_); 2542 return OFFSET_OF(RawContext, num_variables_);
2503 } 2543 }
2504 2544
2505 RawInstance* At(intptr_t context_index) const { 2545 RawInstance* At(intptr_t context_index) const {
2506 return *InstanceAddr(context_index); 2546 return *InstanceAddr(context_index);
2507 } 2547 }
2508 inline void SetAt(intptr_t context_index, const Instance& value) const; 2548 inline void SetAt(intptr_t context_index, const Instance& value) const;
2509 2549
2550 static const intptr_t kBytesPerElement = kWordSize;
2551 static const intptr_t kMaxElements = MAX_ELEMENTS(Context);
2552
2510 static intptr_t variable_offset(intptr_t context_index) { 2553 static intptr_t variable_offset(intptr_t context_index) {
2511 return OFFSET_OF(RawContext, data_[context_index]); 2554 return OFFSET_OF(RawContext, data_[context_index]);
2512 } 2555 }
2513 2556
2514 static intptr_t InstanceSize() { 2557 static intptr_t InstanceSize() {
2515 ASSERT(sizeof(RawContext) == OFFSET_OF(RawContext, data_)); 2558 ASSERT(sizeof(RawContext) == OFFSET_OF(RawContext, data_));
2516 return 0; 2559 return 0;
2517 } 2560 }
2518 2561
2519 static intptr_t InstanceSize(intptr_t num_variables) { 2562 static intptr_t InstanceSize(intptr_t len) {
2520 return RoundedAllocationSize(sizeof(RawContext) + 2563 ASSERT(0 <= len && len <= kMaxElements);
2521 (num_variables * kWordSize)); 2564 return RoundedAllocationSize(sizeof(RawContext) + (len * kBytesPerElement));
2522 } 2565 }
2523 2566
2524 static RawContext* New(intptr_t num_variables, 2567 static RawContext* New(intptr_t num_variables,
2525 Heap::Space space = Heap::kNew); 2568 Heap::Space space = Heap::kNew);
2526 2569
2527 private: 2570 private:
2528 RawInstance** InstanceAddr(intptr_t context_index) const { 2571 RawInstance** InstanceAddr(intptr_t context_index) const {
2529 ASSERT((context_index >= 0) && (context_index < num_variables())); 2572 ASSERT((context_index >= 0) && (context_index < num_variables()));
2530 return &raw_ptr()->data_[context_index]; 2573 return &raw_ptr()->data_[context_index];
2531 } 2574 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2567 2610
2568 RawAbstractType* TypeAt(intptr_t scope_index) const; 2611 RawAbstractType* TypeAt(intptr_t scope_index) const;
2569 void SetTypeAt(intptr_t scope_index, const AbstractType& type) const; 2612 void SetTypeAt(intptr_t scope_index, const AbstractType& type) const;
2570 2613
2571 intptr_t ContextIndexAt(intptr_t scope_index) const; 2614 intptr_t ContextIndexAt(intptr_t scope_index) const;
2572 void SetContextIndexAt(intptr_t scope_index, intptr_t context_index) const; 2615 void SetContextIndexAt(intptr_t scope_index, intptr_t context_index) const;
2573 2616
2574 intptr_t ContextLevelAt(intptr_t scope_index) const; 2617 intptr_t ContextLevelAt(intptr_t scope_index) const;
2575 void SetContextLevelAt(intptr_t scope_index, intptr_t context_level) const; 2618 void SetContextLevelAt(intptr_t scope_index, intptr_t context_level) const;
2576 2619
2620 static const intptr_t kBytesPerElement =
2621 sizeof(RawContextScope::VariableDesc);
2622 static const intptr_t kMaxElements = MAX_ELEMENTS(ContextScope);
2623
2577 static intptr_t InstanceSize() { 2624 static intptr_t InstanceSize() {
2578 ASSERT(sizeof(RawContextScope) == OFFSET_OF(RawContextScope, data_)); 2625 ASSERT(sizeof(RawContextScope) == OFFSET_OF(RawContextScope, data_));
2579 return 0; 2626 return 0;
2580 } 2627 }
2581 2628
2582 static intptr_t InstanceSize(intptr_t num_variables) { 2629 static intptr_t InstanceSize(intptr_t len) {
2583 return RoundedAllocationSize(sizeof(RawContextScope) + 2630 ASSERT(0 <= len && len <= kMaxElements);
2584 (num_variables * sizeof(RawContextScope::VariableDesc))); 2631 return RoundedAllocationSize(
2632 sizeof(RawContextScope) + (len * kBytesPerElement));
2585 } 2633 }
2586 2634
2587 static RawContextScope* New(intptr_t num_variables); 2635 static RawContextScope* New(intptr_t num_variables);
2588 2636
2589 private: 2637 private:
2590 void set_num_variables(intptr_t num_variables) const { 2638 void set_num_variables(intptr_t num_variables) const {
2591 raw_ptr()->num_variables_ = num_variables; 2639 raw_ptr()->num_variables_ = num_variables;
2592 } 2640 }
2593 2641
2594 RawContextScope::VariableDesc* VariableDescAddr(intptr_t index) const { 2642 RawContextScope::VariableDesc* VariableDescAddr(intptr_t index) const {
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
3045 3093
3046 private: 3094 private:
3047 void set_value(int64_t value) const; 3095 void set_value(int64_t value) const;
3048 3096
3049 HEAP_OBJECT_IMPLEMENTATION(Mint, Integer); 3097 HEAP_OBJECT_IMPLEMENTATION(Mint, Integer);
3050 friend class Class; 3098 friend class Class;
3051 }; 3099 };
3052 3100
3053 3101
3054 class Bigint : public Integer { 3102 class Bigint : public Integer {
3103 private:
3104 typedef uint32_t Chunk;
3105 typedef uint64_t DoubleChunk;
3106 static const int kChunkSize = sizeof(Chunk);
3107
3055 public: 3108 public:
3056 virtual bool IsZero() const { return raw_ptr()->signed_length_ == 0; } 3109 virtual bool IsZero() const { return raw_ptr()->signed_length_ == 0; }
3057 virtual bool IsNegative() const { return raw_ptr()->signed_length_ < 0; } 3110 virtual bool IsNegative() const { return raw_ptr()->signed_length_ < 0; }
3058 3111
3059 virtual bool Equals(const Instance& other) const; 3112 virtual bool Equals(const Instance& other) const;
3060 3113
3061 virtual double AsDoubleValue() const; 3114 virtual double AsDoubleValue() const;
3062 virtual int64_t AsInt64Value() const; 3115 virtual int64_t AsInt64Value() const;
3063 3116
3064 virtual int CompareWith(const Integer& other) const; 3117 virtual int CompareWith(const Integer& other) const;
3065 3118
3066 static intptr_t InstanceSize(intptr_t length) { 3119 static const intptr_t kBytesPerElement = kChunkSize;
3067 ASSERT(length >= 0); 3120 static const intptr_t kMaxElements = MAX_ELEMENTS(Bigint);
3068 return RoundedAllocationSize(sizeof(RawBigint) + (length * sizeof(Chunk))); 3121
3122 static intptr_t InstanceSize() { return 0; }
3123
3124 static intptr_t InstanceSize(intptr_t len) {
3125 ASSERT(0 <= len && len <= kMaxElements);
3126 return RoundedAllocationSize(sizeof(RawBigint) + (len * kBytesPerElement));
3069 } 3127 }
3070 static intptr_t InstanceSize() { return 0; }
3071 3128
3072 static RawBigint* New(const String& str, Heap::Space space = Heap::kNew); 3129 static RawBigint* New(const String& str, Heap::Space space = Heap::kNew);
3073 static RawBigint* New(int64_t value, Heap::Space space = Heap::kNew); 3130 static RawBigint* New(int64_t value, Heap::Space space = Heap::kNew);
3074 3131
3075 private: 3132 private:
3076 typedef uint32_t Chunk;
3077 typedef uint64_t DoubleChunk;
3078 static const int kChunkSize = sizeof(Chunk);
3079
3080 Chunk GetChunkAt(intptr_t i) const { 3133 Chunk GetChunkAt(intptr_t i) const {
3081 return *ChunkAddr(i); 3134 return *ChunkAddr(i);
3082 } 3135 }
3083 3136
3084 void SetChunkAt(intptr_t i, Chunk newValue) const { 3137 void SetChunkAt(intptr_t i, Chunk newValue) const {
3085 *ChunkAddr(i) = newValue; 3138 *ChunkAddr(i) = newValue;
3086 } 3139 }
3087 3140
3088 // Returns the number of chunks in use. 3141 // Returns the number of chunks in use.
3089 intptr_t Length() const { 3142 intptr_t Length() const {
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
3329 virtual int32_t CharAt(intptr_t index) const { 3382 virtual int32_t CharAt(intptr_t index) const {
3330 return *CharAddr(index); 3383 return *CharAddr(index);
3331 } 3384 }
3332 3385
3333 virtual intptr_t CharSize() const { 3386 virtual intptr_t CharSize() const {
3334 return kOneByteChar; 3387 return kOneByteChar;
3335 } 3388 }
3336 3389
3337 RawOneByteString* EscapeDoubleQuotes() const; 3390 RawOneByteString* EscapeDoubleQuotes() const;
3338 3391
3392 static const intptr_t kBytesPerElement = 1;
3393 static const intptr_t kMaxElements = MAX_ELEMENTS(OneByteString);
3394
3339 static intptr_t data_offset() { return OFFSET_OF(RawOneByteString, data_); } 3395 static intptr_t data_offset() { return OFFSET_OF(RawOneByteString, data_); }
3340 3396
3341 static intptr_t InstanceSize() { 3397 static intptr_t InstanceSize() {
3342 ASSERT(sizeof(RawOneByteString) == OFFSET_OF(RawOneByteString, data_)); 3398 ASSERT(sizeof(RawOneByteString) == OFFSET_OF(RawOneByteString, data_));
3343 return 0; 3399 return 0;
3344 } 3400 }
3345 3401
3346 static intptr_t InstanceSize(intptr_t len) { 3402 static intptr_t InstanceSize(intptr_t len) {
3347 return RoundedAllocationSize(sizeof(RawOneByteString) + len); 3403 ASSERT(0 <= len && len <= kMaxElements);
3404 return RoundedAllocationSize(
3405 sizeof(RawOneByteString) + (len * kBytesPerElement));
3348 } 3406 }
3349 3407
3350 static RawOneByteString* New(intptr_t len, 3408 static RawOneByteString* New(intptr_t len,
3351 Heap::Space space); 3409 Heap::Space space);
3352 static RawOneByteString* New(const uint8_t* characters, 3410 static RawOneByteString* New(const uint8_t* characters,
3353 intptr_t len, 3411 intptr_t len,
3354 Heap::Space space); 3412 Heap::Space space);
3355 static RawOneByteString* New(const uint16_t* characters, 3413 static RawOneByteString* New(const uint16_t* characters,
3356 intptr_t len, 3414 intptr_t len,
3357 Heap::Space space); 3415 Heap::Space space);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3390 virtual int32_t CharAt(intptr_t index) const { 3448 virtual int32_t CharAt(intptr_t index) const {
3391 return *CharAddr(index); 3449 return *CharAddr(index);
3392 } 3450 }
3393 3451
3394 virtual intptr_t CharSize() const { 3452 virtual intptr_t CharSize() const {
3395 return kTwoByteChar; 3453 return kTwoByteChar;
3396 } 3454 }
3397 3455
3398 RawTwoByteString* EscapeDoubleQuotes() const; 3456 RawTwoByteString* EscapeDoubleQuotes() const;
3399 3457
3458 static const intptr_t kBytesPerElement = 2;
3459 static const intptr_t kMaxElements = MAX_ELEMENTS(TwoByteString);
3460
3400 static intptr_t InstanceSize() { 3461 static intptr_t InstanceSize() {
3401 ASSERT(sizeof(RawTwoByteString) == OFFSET_OF(RawTwoByteString, data_)); 3462 ASSERT(sizeof(RawTwoByteString) == OFFSET_OF(RawTwoByteString, data_));
3402 return 0; 3463 return 0;
3403 } 3464 }
3404 3465
3405 static intptr_t InstanceSize(intptr_t len) { 3466 static intptr_t InstanceSize(intptr_t len) {
3406 return RoundedAllocationSize(sizeof(RawTwoByteString) + (2 * len)); 3467 ASSERT(0 <= len && len <= kMaxElements);
3468 return RoundedAllocationSize(
3469 sizeof(RawTwoByteString) + (len * kBytesPerElement));
3407 } 3470 }
3408 3471
3409 static RawTwoByteString* New(intptr_t len, 3472 static RawTwoByteString* New(intptr_t len,
3410 Heap::Space space); 3473 Heap::Space space);
3411 static RawTwoByteString* New(const uint16_t* characters, 3474 static RawTwoByteString* New(const uint16_t* characters,
3412 intptr_t len, 3475 intptr_t len,
3413 Heap::Space space); 3476 Heap::Space space);
3414 static RawTwoByteString* New(const uint32_t* characters, 3477 static RawTwoByteString* New(const uint32_t* characters,
3415 intptr_t len, 3478 intptr_t len,
3416 Heap::Space space); 3479 Heap::Space space);
(...skipping 28 matching lines...) Expand all
3445 virtual int32_t CharAt(intptr_t index) const { 3508 virtual int32_t CharAt(intptr_t index) const {
3446 return *CharAddr(index); 3509 return *CharAddr(index);
3447 } 3510 }
3448 3511
3449 virtual intptr_t CharSize() const { 3512 virtual intptr_t CharSize() const {
3450 return kFourByteChar; 3513 return kFourByteChar;
3451 } 3514 }
3452 3515
3453 RawFourByteString* EscapeDoubleQuotes() const; 3516 RawFourByteString* EscapeDoubleQuotes() const;
3454 3517
3518 static const intptr_t kBytesPerElement = 4;
3519 static const intptr_t kMaxElements = MAX_ELEMENTS(FourByteString);
3520
3455 static intptr_t InstanceSize() { 3521 static intptr_t InstanceSize() {
3456 ASSERT(sizeof(RawFourByteString) == OFFSET_OF(RawFourByteString, data_)); 3522 ASSERT(sizeof(RawFourByteString) == OFFSET_OF(RawFourByteString, data_));
3457 return 0; 3523 return 0;
3458 } 3524 }
3459 3525
3460 static intptr_t InstanceSize(intptr_t len) { 3526 static intptr_t InstanceSize(intptr_t len) {
3461 return RoundedAllocationSize(sizeof(RawFourByteString) + (4 * len)); 3527 ASSERT(0 <= len && len <= kMaxElements);
3528 return RoundedAllocationSize(
3529 sizeof(RawFourByteString) + (len * kBytesPerElement));
3462 } 3530 }
3463 3531
3464 static RawFourByteString* New(intptr_t len, 3532 static RawFourByteString* New(intptr_t len,
3465 Heap::Space space); 3533 Heap::Space space);
3466 static RawFourByteString* New(const uint32_t* characters, 3534 static RawFourByteString* New(const uint32_t* characters,
3467 intptr_t len, 3535 intptr_t len,
3468 Heap::Space space); 3536 Heap::Space space);
3469 static RawFourByteString* New(const FourByteString& str, 3537 static RawFourByteString* New(const FourByteString& str,
3470 Heap::Space space); 3538 Heap::Space space);
3471 3539
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
3544 3612
3545 virtual intptr_t CharSize() const { 3613 virtual intptr_t CharSize() const {
3546 return kTwoByteChar; 3614 return kTwoByteChar;
3547 } 3615 }
3548 3616
3549 virtual bool IsExternal() const { return true; } 3617 virtual bool IsExternal() const { return true; }
3550 virtual void* GetPeer() const { 3618 virtual void* GetPeer() const {
3551 return raw_ptr()->external_data_->peer(); 3619 return raw_ptr()->external_data_->peer();
3552 } 3620 }
3553 3621
3622 static const intptr_t kBytesPerElement = 2;
3623 static const intptr_t kMaxElements = (kIntptrMax / kBytesPerElement);
3624
3554 static intptr_t InstanceSize() { 3625 static intptr_t InstanceSize() {
3555 return RoundedAllocationSize(sizeof(RawExternalTwoByteString)); 3626 return RoundedAllocationSize(sizeof(RawExternalTwoByteString));
3556 } 3627 }
3557 3628
3558 static RawExternalTwoByteString* New(const uint16_t* characters, 3629 static RawExternalTwoByteString* New(const uint16_t* characters,
3559 intptr_t len, 3630 intptr_t len,
3560 void* peer, 3631 void* peer,
3561 Dart_PeerFinalizer callback, 3632 Dart_PeerFinalizer callback,
3562 Heap::Space space = Heap::kNew); 3633 Heap::Space space = Heap::kNew);
3563 3634
(...skipping 24 matching lines...) Expand all
3588 3659
3589 virtual intptr_t CharSize() const { 3660 virtual intptr_t CharSize() const {
3590 return kFourByteChar; 3661 return kFourByteChar;
3591 } 3662 }
3592 3663
3593 virtual bool IsExternal() const { return true; } 3664 virtual bool IsExternal() const { return true; }
3594 virtual void* GetPeer() const { 3665 virtual void* GetPeer() const {
3595 return raw_ptr()->external_data_->peer(); 3666 return raw_ptr()->external_data_->peer();
3596 } 3667 }
3597 3668
3669 static const intptr_t kBytesPerElement = 4;
3670 static const intptr_t kMaxElements = (kIntptrMax / kBytesPerElement);
3671
3598 static intptr_t InstanceSize() { 3672 static intptr_t InstanceSize() {
3599 return RoundedAllocationSize(sizeof(RawExternalFourByteString)); 3673 return RoundedAllocationSize(sizeof(RawExternalFourByteString));
3600 } 3674 }
3601 3675
3602 static RawExternalFourByteString* New(const uint32_t* characters, 3676 static RawExternalFourByteString* New(const uint32_t* characters,
3603 intptr_t len, 3677 intptr_t len,
3604 void* peer, 3678 void* peer,
3605 Dart_PeerFinalizer callback, 3679 Dart_PeerFinalizer callback,
3606 Heap::Space space = Heap::kNew); 3680 Heap::Space space = Heap::kNew);
3607 3681
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3672 3746
3673 virtual RawAbstractTypeArguments* GetTypeArguments() const { 3747 virtual RawAbstractTypeArguments* GetTypeArguments() const {
3674 return raw_ptr()->type_arguments_; 3748 return raw_ptr()->type_arguments_;
3675 } 3749 }
3676 virtual void SetTypeArguments(const AbstractTypeArguments& value) const { 3750 virtual void SetTypeArguments(const AbstractTypeArguments& value) const {
3677 raw_ptr()->type_arguments_ = value.raw(); 3751 raw_ptr()->type_arguments_ = value.raw();
3678 } 3752 }
3679 3753
3680 virtual bool Equals(const Instance& other) const; 3754 virtual bool Equals(const Instance& other) const;
3681 3755
3756 static const intptr_t kBytesPerElement = kWordSize;
3757 static const intptr_t kMaxElements = MAX_ELEMENTS(Array);
3758
3682 static intptr_t type_arguments_offset() { 3759 static intptr_t type_arguments_offset() {
3683 return OFFSET_OF(RawArray, type_arguments_); 3760 return OFFSET_OF(RawArray, type_arguments_);
3684 } 3761 }
3685 3762
3686 static intptr_t InstanceSize() { 3763 static intptr_t InstanceSize() {
3687 ASSERT(sizeof(RawArray) == OFFSET_OF_RETURNED_VALUE(RawArray, data)); 3764 ASSERT(sizeof(RawArray) == OFFSET_OF_RETURNED_VALUE(RawArray, data));
3688 return 0; 3765 return 0;
3689 } 3766 }
3690 3767
3691 static intptr_t InstanceSize(intptr_t len) { 3768 static intptr_t InstanceSize(intptr_t len) {
3692 // Ensure that variable length data is not adding to the object length. 3769 // Ensure that variable length data is not adding to the object length.
3693 ASSERT(sizeof(RawArray) == (sizeof(RawObject) + (2 * kWordSize))); 3770 ASSERT(sizeof(RawArray) == (sizeof(RawObject) + (2 * kWordSize)));
3694 return RoundedAllocationSize(sizeof(RawArray) + (len * kWordSize)); 3771 ASSERT(0 <= len && len <= kMaxElements);
3772 return RoundedAllocationSize(sizeof(RawArray) + (len * kBytesPerElement));
3695 } 3773 }
3696 3774
3697 // Make the array immutable to Dart code by switching the class pointer 3775 // Make the array immutable to Dart code by switching the class pointer
3698 // to ImmutableArray. 3776 // to ImmutableArray.
3699 void MakeImmutable() const; 3777 void MakeImmutable() const;
3700 3778
3701 static RawArray* New(intptr_t len, Heap::Space space = Heap::kNew); 3779 static RawArray* New(intptr_t len, Heap::Space space = Heap::kNew);
3702 3780
3703 // Creates and returns a new array with 'new_length'. Copies all elements from 3781 // Creates and returns a new array with 'new_length'. Copies all elements from
3704 // 'source' to the new array. 'new_length' must be greater than or equal to 3782 // 'source' to the new array. 'new_length' must be greater than or equal to
(...skipping 14 matching lines...) Expand all
3719 // collection. The backing array of the original Growable Object Array is 3797 // collection. The backing array of the original Growable Object Array is
3720 // set to an empty array. 3798 // set to an empty array.
3721 static RawArray* MakeArray(const GrowableObjectArray& growable_array); 3799 static RawArray* MakeArray(const GrowableObjectArray& growable_array);
3722 3800
3723 protected: 3801 protected:
3724 static RawArray* New(const Class& cls, 3802 static RawArray* New(const Class& cls,
3725 intptr_t len, 3803 intptr_t len,
3726 Heap::Space space = Heap::kNew); 3804 Heap::Space space = Heap::kNew);
3727 3805
3728 private: 3806 private:
3729 // Make sure that the array size cannot wrap around.
3730 static const intptr_t kMaxArrayElements = 512 * 1024 * 1024;
3731
3732 RawObject** ObjectAddr(intptr_t index) const { 3807 RawObject** ObjectAddr(intptr_t index) const {
3733 // TODO(iposva): Determine if we should throw an exception here. 3808 // TODO(iposva): Determine if we should throw an exception here.
3734 ASSERT((index >= 0) && (index < Length())); 3809 ASSERT((index >= 0) && (index < Length()));
3735 return &raw_ptr()->data()[index]; 3810 return &raw_ptr()->data()[index];
3736 } 3811 }
3737 3812
3738 void SetLength(intptr_t value) const { 3813 void SetLength(intptr_t value) const {
3739 // This is only safe because we create a new Smi, which does not cause 3814 // This is only safe because we create a new Smi, which does not cause
3740 // heap allocation. 3815 // heap allocation.
3741 raw_ptr()->length_ = Smi::New(value); 3816 raw_ptr()->length_ = Smi::New(value);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
3923 int8_t At(intptr_t index) const { 3998 int8_t At(intptr_t index) const {
3924 ASSERT((index >= 0) && (index < Length())); 3999 ASSERT((index >= 0) && (index < Length()));
3925 return raw_ptr()->data_[index]; 4000 return raw_ptr()->data_[index];
3926 } 4001 }
3927 4002
3928 void SetAt(intptr_t index, int8_t value) const { 4003 void SetAt(intptr_t index, int8_t value) const {
3929 ASSERT((index >= 0) && (index < Length())); 4004 ASSERT((index >= 0) && (index < Length()));
3930 raw_ptr()->data_[index] = value; 4005 raw_ptr()->data_[index] = value;
3931 } 4006 }
3932 4007
4008 static const intptr_t kBytesPerElement = 1;
4009 static const intptr_t kMaxElements = MAX_ELEMENTS(Int8Array);
4010
3933 static intptr_t data_offset() { 4011 static intptr_t data_offset() {
3934 return length_offset() + kWordSize; 4012 return length_offset() + kWordSize;
3935 } 4013 }
3936 4014
3937 static intptr_t InstanceSize() { 4015 static intptr_t InstanceSize() {
3938 ASSERT(sizeof(RawInt8Array) == OFFSET_OF(RawInt8Array, data_)); 4016 ASSERT(sizeof(RawInt8Array) == OFFSET_OF(RawInt8Array, data_));
3939 return 0; 4017 return 0;
3940 } 4018 }
3941 4019
3942 static intptr_t InstanceSize(intptr_t len) { 4020 static intptr_t InstanceSize(intptr_t len) {
3943 return RoundedAllocationSize(sizeof(RawInt8Array) + len); 4021 ASSERT(0 <= len && len <= kMaxElements);
4022 return RoundedAllocationSize(
4023 sizeof(RawInt8Array) + (len * kBytesPerElement));
3944 } 4024 }
3945 4025
3946 static RawInt8Array* New(intptr_t len, 4026 static RawInt8Array* New(intptr_t len,
3947 Heap::Space space = Heap::kNew); 4027 Heap::Space space = Heap::kNew);
3948 static RawInt8Array* New(const int8_t* data, 4028 static RawInt8Array* New(const int8_t* data,
3949 intptr_t len, 4029 intptr_t len,
3950 Heap::Space space = Heap::kNew); 4030 Heap::Space space = Heap::kNew);
3951 4031
3952 private: 4032 private:
3953 uint8_t* ByteAddr(intptr_t byte_offset) const { 4033 uint8_t* ByteAddr(intptr_t byte_offset) const {
(...skipping 16 matching lines...) Expand all
3970 uint8_t At(intptr_t index) const { 4050 uint8_t At(intptr_t index) const {
3971 ASSERT((index >= 0) && (index < Length())); 4051 ASSERT((index >= 0) && (index < Length()));
3972 return raw_ptr()->data_[index]; 4052 return raw_ptr()->data_[index];
3973 } 4053 }
3974 4054
3975 void SetAt(intptr_t index, uint8_t value) const { 4055 void SetAt(intptr_t index, uint8_t value) const {
3976 ASSERT((index >= 0) && (index < Length())); 4056 ASSERT((index >= 0) && (index < Length()));
3977 raw_ptr()->data_[index] = value; 4057 raw_ptr()->data_[index] = value;
3978 } 4058 }
3979 4059
4060 static const intptr_t kBytesPerElement = 1;
4061 static const intptr_t kMaxElements = MAX_ELEMENTS(Uint8Array);
4062
3980 static intptr_t data_offset() { 4063 static intptr_t data_offset() {
3981 return length_offset() + kWordSize; 4064 return length_offset() + kWordSize;
3982 } 4065 }
3983 4066
3984 static intptr_t InstanceSize() { 4067 static intptr_t InstanceSize() {
3985 ASSERT(sizeof(RawUint8Array) == OFFSET_OF(RawUint8Array, data_)); 4068 ASSERT(sizeof(RawUint8Array) == OFFSET_OF(RawUint8Array, data_));
3986 return 0; 4069 return 0;
3987 } 4070 }
3988 4071
3989 static intptr_t InstanceSize(intptr_t len) { 4072 static intptr_t InstanceSize(intptr_t len) {
3990 return RoundedAllocationSize(sizeof(RawUint8Array) + len); 4073 ASSERT(0 <= len && len <= kMaxElements);
4074 return RoundedAllocationSize(
4075 sizeof(RawUint8Array) + (len * kBytesPerElement));
3991 } 4076 }
3992 4077
3993 static RawUint8Array* New(intptr_t len, 4078 static RawUint8Array* New(intptr_t len,
3994 Heap::Space space = Heap::kNew); 4079 Heap::Space space = Heap::kNew);
3995 static RawUint8Array* New(const uint8_t* data, 4080 static RawUint8Array* New(const uint8_t* data,
3996 intptr_t len, 4081 intptr_t len,
3997 Heap::Space space = Heap::kNew); 4082 Heap::Space space = Heap::kNew);
3998 4083
3999 private: 4084 private:
4000 uint8_t* ByteAddr(intptr_t byte_offset) const { 4085 uint8_t* ByteAddr(intptr_t byte_offset) const {
(...skipping 16 matching lines...) Expand all
4017 int16_t At(intptr_t index) const { 4102 int16_t At(intptr_t index) const {
4018 ASSERT((index >= 0) && (index < Length())); 4103 ASSERT((index >= 0) && (index < Length()));
4019 return raw_ptr()->data_[index]; 4104 return raw_ptr()->data_[index];
4020 } 4105 }
4021 4106
4022 void SetAt(intptr_t index, int16_t value) const { 4107 void SetAt(intptr_t index, int16_t value) const {
4023 ASSERT((index >= 0) && (index < Length())); 4108 ASSERT((index >= 0) && (index < Length()));
4024 raw_ptr()->data_[index] = value; 4109 raw_ptr()->data_[index] = value;
4025 } 4110 }
4026 4111
4112 static const intptr_t kBytesPerElement = 2;
4113 static const intptr_t kMaxElements = MAX_ELEMENTS(Int16Array);
4114
4027 static intptr_t data_offset() { 4115 static intptr_t data_offset() {
4028 return length_offset() + kWordSize; 4116 return length_offset() + kWordSize;
4029 } 4117 }
4030 4118
4031 static intptr_t InstanceSize() { 4119 static intptr_t InstanceSize() {
4032 ASSERT(sizeof(RawInt16Array) == OFFSET_OF(RawInt16Array, data_)); 4120 ASSERT(sizeof(RawInt16Array) == OFFSET_OF(RawInt16Array, data_));
4033 return 0; 4121 return 0;
4034 } 4122 }
4035 4123
4036 static intptr_t InstanceSize(intptr_t len) { 4124 static intptr_t InstanceSize(intptr_t len) {
4037 intptr_t data_size = len * kBytesPerElement; 4125 ASSERT(0 <= len && len <= kMaxElements);
4038 return RoundedAllocationSize(sizeof(RawInt16Array) + data_size); 4126 return RoundedAllocationSize(
4127 sizeof(RawInt16Array) + (len * kBytesPerElement));
4039 } 4128 }
4040 4129
4041 static RawInt16Array* New(intptr_t len, 4130 static RawInt16Array* New(intptr_t len,
4042 Heap::Space space = Heap::kNew); 4131 Heap::Space space = Heap::kNew);
4043 static RawInt16Array* New(const int16_t* data, 4132 static RawInt16Array* New(const int16_t* data,
4044 intptr_t len, 4133 intptr_t len,
4045 Heap::Space space = Heap::kNew); 4134 Heap::Space space = Heap::kNew);
4046 4135
4047 private: 4136 private:
4048 static const intptr_t kBytesPerElement = 2;
4049
4050 uint8_t* ByteAddr(intptr_t byte_offset) const { 4137 uint8_t* ByteAddr(intptr_t byte_offset) const {
4051 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); 4138 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength()));
4052 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; 4139 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset;
4053 } 4140 }
4054 4141
4055 HEAP_OBJECT_IMPLEMENTATION(Int16Array, ByteArray); 4142 HEAP_OBJECT_IMPLEMENTATION(Int16Array, ByteArray);
4056 friend class ByteArray; 4143 friend class ByteArray;
4057 friend class Class; 4144 friend class Class;
4058 }; 4145 };
4059 4146
4060 4147
4061 class Uint16Array : public ByteArray { 4148 class Uint16Array : public ByteArray {
4062 public: 4149 public:
4063 intptr_t ByteLength() const { 4150 intptr_t ByteLength() const {
4064 return Length() * kBytesPerElement; 4151 return Length() * kBytesPerElement;
4065 } 4152 }
4066 4153
4067 uint16_t At(intptr_t index) const { 4154 uint16_t At(intptr_t index) const {
4068 ASSERT((index >= 0) && (index < Length())); 4155 ASSERT((index >= 0) && (index < Length()));
4069 return raw_ptr()->data_[index]; 4156 return raw_ptr()->data_[index];
4070 } 4157 }
4071 4158
4072 void SetAt(intptr_t index, uint16_t value) const { 4159 void SetAt(intptr_t index, uint16_t value) const {
4073 ASSERT((index >= 0) && (index < Length())); 4160 ASSERT((index >= 0) && (index < Length()));
4074 raw_ptr()->data_[index] = value; 4161 raw_ptr()->data_[index] = value;
4075 } 4162 }
4076 4163
4164 static const intptr_t kBytesPerElement = 2;
4165 static const intptr_t kMaxElements = MAX_ELEMENTS(Uint16Array);
4166
4077 static intptr_t data_offset() { 4167 static intptr_t data_offset() {
4078 return length_offset() + kWordSize; 4168 return length_offset() + kWordSize;
4079 } 4169 }
4080 4170
4081 static intptr_t InstanceSize() { 4171 static intptr_t InstanceSize() {
4082 ASSERT(sizeof(RawUint16Array) == OFFSET_OF(RawUint16Array, data_)); 4172 ASSERT(sizeof(RawUint16Array) == OFFSET_OF(RawUint16Array, data_));
4083 return 0; 4173 return 0;
4084 } 4174 }
4085 4175
4086 static intptr_t InstanceSize(intptr_t len) { 4176 static intptr_t InstanceSize(intptr_t len) {
4087 intptr_t data_size = len * kBytesPerElement; 4177 ASSERT(0 <= len && len <= kMaxElements);
4088 return RoundedAllocationSize(sizeof(RawUint16Array) + data_size); 4178 return RoundedAllocationSize(
4179 sizeof(RawUint16Array) + (len * kBytesPerElement));
4089 } 4180 }
4090 4181
4091 static RawUint16Array* New(intptr_t len, 4182 static RawUint16Array* New(intptr_t len,
4092 Heap::Space space = Heap::kNew); 4183 Heap::Space space = Heap::kNew);
4093 static RawUint16Array* New(const uint16_t* data, 4184 static RawUint16Array* New(const uint16_t* data,
4094 intptr_t len, 4185 intptr_t len,
4095 Heap::Space space = Heap::kNew); 4186 Heap::Space space = Heap::kNew);
4096 4187
4097 private: 4188 private:
4098 static const intptr_t kBytesPerElement = 2;
4099
4100 uint8_t* ByteAddr(intptr_t byte_offset) const { 4189 uint8_t* ByteAddr(intptr_t byte_offset) const {
4101 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); 4190 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength()));
4102 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; 4191 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset;
4103 } 4192 }
4104 4193
4105 HEAP_OBJECT_IMPLEMENTATION(Uint16Array, ByteArray); 4194 HEAP_OBJECT_IMPLEMENTATION(Uint16Array, ByteArray);
4106 friend class ByteArray; 4195 friend class ByteArray;
4107 friend class Class; 4196 friend class Class;
4108 }; 4197 };
4109 4198
4110 4199
4111 class Int32Array : public ByteArray { 4200 class Int32Array : public ByteArray {
4112 public: 4201 public:
4113 intptr_t ByteLength() const { 4202 intptr_t ByteLength() const {
4114 return Length() * kBytesPerElement; 4203 return Length() * kBytesPerElement;
4115 } 4204 }
4116 4205
4117 int32_t At(intptr_t index) const { 4206 int32_t At(intptr_t index) const {
4118 ASSERT((index >= 0) && (index < Length())); 4207 ASSERT((index >= 0) && (index < Length()));
4119 return raw_ptr()->data_[index]; 4208 return raw_ptr()->data_[index];
4120 } 4209 }
4121 4210
4122 void SetAt(intptr_t index, int32_t value) const { 4211 void SetAt(intptr_t index, int32_t value) const {
4123 ASSERT((index >= 0) && (index < Length())); 4212 ASSERT((index >= 0) && (index < Length()));
4124 raw_ptr()->data_[index] = value; 4213 raw_ptr()->data_[index] = value;
4125 } 4214 }
4126 4215
4216 static const intptr_t kBytesPerElement = 4;
4217 static const intptr_t kMaxElements = MAX_ELEMENTS(Int32Array);
4218
4127 static intptr_t data_offset() { 4219 static intptr_t data_offset() {
4128 return length_offset() + kWordSize; 4220 return length_offset() + kWordSize;
4129 } 4221 }
4130 4222
4131 static intptr_t InstanceSize() { 4223 static intptr_t InstanceSize() {
4132 ASSERT(sizeof(RawInt32Array) == OFFSET_OF(RawInt32Array, data_)); 4224 ASSERT(sizeof(RawInt32Array) == OFFSET_OF(RawInt32Array, data_));
4133 return 0; 4225 return 0;
4134 } 4226 }
4135 4227
4136 static intptr_t InstanceSize(intptr_t len) { 4228 static intptr_t InstanceSize(intptr_t len) {
4137 intptr_t data_size = len * kBytesPerElement; 4229 ASSERT(0 <= len && len <= kMaxElements);
4138 return RoundedAllocationSize(sizeof(RawInt32Array) + data_size); 4230 return RoundedAllocationSize(
4231 sizeof(RawInt32Array) + (len * kBytesPerElement));
4139 } 4232 }
4140 4233
4141 static RawInt32Array* New(intptr_t len, 4234 static RawInt32Array* New(intptr_t len,
4142 Heap::Space space = Heap::kNew); 4235 Heap::Space space = Heap::kNew);
4143 static RawInt32Array* New(const int32_t* data, 4236 static RawInt32Array* New(const int32_t* data,
4144 intptr_t len, 4237 intptr_t len,
4145 Heap::Space space = Heap::kNew); 4238 Heap::Space space = Heap::kNew);
4146 4239
4147 private: 4240 private:
4148 static const intptr_t kBytesPerElement = 4;
4149
4150 uint8_t* ByteAddr(intptr_t byte_offset) const { 4241 uint8_t* ByteAddr(intptr_t byte_offset) const {
4151 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); 4242 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength()));
4152 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; 4243 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset;
4153 } 4244 }
4154 4245
4155 HEAP_OBJECT_IMPLEMENTATION(Int32Array, ByteArray); 4246 HEAP_OBJECT_IMPLEMENTATION(Int32Array, ByteArray);
4156 friend class ByteArray; 4247 friend class ByteArray;
4157 friend class Class; 4248 friend class Class;
4158 }; 4249 };
4159 4250
4160 4251
4161 class Uint32Array : public ByteArray { 4252 class Uint32Array : public ByteArray {
4162 public: 4253 public:
4163 intptr_t ByteLength() const { 4254 intptr_t ByteLength() const {
4164 return Length() * kBytesPerElement; 4255 return Length() * kBytesPerElement;
4165 } 4256 }
4166 4257
4167 uint32_t At(intptr_t index) const { 4258 uint32_t At(intptr_t index) const {
4168 ASSERT((index >= 0) && (index < Length())); 4259 ASSERT((index >= 0) && (index < Length()));
4169 return raw_ptr()->data_[index]; 4260 return raw_ptr()->data_[index];
4170 } 4261 }
4171 4262
4172 void SetAt(intptr_t index, uint32_t value) const { 4263 void SetAt(intptr_t index, uint32_t value) const {
4173 ASSERT((index >= 0) && (index < Length())); 4264 ASSERT((index >= 0) && (index < Length()));
4174 raw_ptr()->data_[index] = value; 4265 raw_ptr()->data_[index] = value;
4175 } 4266 }
4176 4267
4268 static const intptr_t kBytesPerElement = 4;
4269 static const intptr_t kMaxElements = MAX_ELEMENTS(Uint32Array);
4270
4177 static intptr_t data_offset() { 4271 static intptr_t data_offset() {
4178 return length_offset() + kWordSize; 4272 return length_offset() + kWordSize;
4179 } 4273 }
4180 4274
4181 static intptr_t InstanceSize() { 4275 static intptr_t InstanceSize() {
4182 ASSERT(sizeof(RawUint32Array) == OFFSET_OF(RawUint32Array, data_)); 4276 ASSERT(sizeof(RawUint32Array) == OFFSET_OF(RawUint32Array, data_));
4183 return 0; 4277 return 0;
4184 } 4278 }
4185 4279
4186 static intptr_t InstanceSize(intptr_t len) { 4280 static intptr_t InstanceSize(intptr_t len) {
4187 intptr_t data_size = len * kBytesPerElement; 4281 ASSERT(0 <= len && len <= kMaxElements);
4188 return RoundedAllocationSize(sizeof(RawUint32Array) + data_size); 4282 return RoundedAllocationSize(
4283 sizeof(RawUint32Array) + (len * kBytesPerElement));
4189 } 4284 }
4190 4285
4191 static RawUint32Array* New(intptr_t len, 4286 static RawUint32Array* New(intptr_t len,
4192 Heap::Space space = Heap::kNew); 4287 Heap::Space space = Heap::kNew);
4193 static RawUint32Array* New(const uint32_t* data, 4288 static RawUint32Array* New(const uint32_t* data,
4194 intptr_t len, 4289 intptr_t len,
4195 Heap::Space space = Heap::kNew); 4290 Heap::Space space = Heap::kNew);
4196 4291
4197 private: 4292 private:
4198 static const intptr_t kBytesPerElement = 4;
4199
4200 uint8_t* ByteAddr(intptr_t byte_offset) const { 4293 uint8_t* ByteAddr(intptr_t byte_offset) const {
4201 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); 4294 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength()));
4202 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; 4295 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset;
4203 } 4296 }
4204 4297
4205 HEAP_OBJECT_IMPLEMENTATION(Uint32Array, ByteArray); 4298 HEAP_OBJECT_IMPLEMENTATION(Uint32Array, ByteArray);
4206 friend class ByteArray; 4299 friend class ByteArray;
4207 friend class Class; 4300 friend class Class;
4208 }; 4301 };
4209 4302
4210 4303
4211 class Int64Array : public ByteArray { 4304 class Int64Array : public ByteArray {
4212 public: 4305 public:
4213 intptr_t ByteLength() const { 4306 intptr_t ByteLength() const {
4214 return Length() * kBytesPerElement; 4307 return Length() * kBytesPerElement;
4215 } 4308 }
4216 4309
4217 int64_t At(intptr_t index) const { 4310 int64_t At(intptr_t index) const {
4218 ASSERT((index >= 0) && (index < Length())); 4311 ASSERT((index >= 0) && (index < Length()));
4219 return raw_ptr()->data_[index]; 4312 return raw_ptr()->data_[index];
4220 } 4313 }
4221 4314
4222 void SetAt(intptr_t index, int64_t value) const { 4315 void SetAt(intptr_t index, int64_t value) const {
4223 ASSERT((index >= 0) && (index < Length())); 4316 ASSERT((index >= 0) && (index < Length()));
4224 raw_ptr()->data_[index] = value; 4317 raw_ptr()->data_[index] = value;
4225 } 4318 }
4226 4319
4320 static const intptr_t kBytesPerElement = 8;
4321 static const intptr_t kMaxElements = MAX_ELEMENTS(Int64Array);
4322
4227 static intptr_t data_offset() { 4323 static intptr_t data_offset() {
4228 return length_offset() + kWordSize; 4324 return length_offset() + kWordSize;
4229 } 4325 }
4230 4326
4231 static intptr_t InstanceSize() { 4327 static intptr_t InstanceSize() {
4232 ASSERT(sizeof(RawInt64Array) == OFFSET_OF(RawInt64Array, data_)); 4328 ASSERT(sizeof(RawInt64Array) == OFFSET_OF(RawInt64Array, data_));
4233 return 0; 4329 return 0;
4234 } 4330 }
4235 4331
4236 static intptr_t InstanceSize(intptr_t len) { 4332 static intptr_t InstanceSize(intptr_t len) {
4237 intptr_t data_size = len * kBytesPerElement; 4333 ASSERT(0 <= len && len <= kMaxElements);
4238 return RoundedAllocationSize(sizeof(RawInt64Array) + data_size); 4334 return RoundedAllocationSize(
4335 sizeof(RawInt64Array) + (len * kBytesPerElement));
4239 } 4336 }
4240 4337
4241 static RawInt64Array* New(intptr_t len, 4338 static RawInt64Array* New(intptr_t len,
4242 Heap::Space space = Heap::kNew); 4339 Heap::Space space = Heap::kNew);
4243 static RawInt64Array* New(const int64_t* data, 4340 static RawInt64Array* New(const int64_t* data,
4244 intptr_t len, 4341 intptr_t len,
4245 Heap::Space space = Heap::kNew); 4342 Heap::Space space = Heap::kNew);
4246 4343
4247 private: 4344 private:
4248 static const intptr_t kBytesPerElement = 8;
4249
4250 uint8_t* ByteAddr(intptr_t byte_offset) const { 4345 uint8_t* ByteAddr(intptr_t byte_offset) const {
4251 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); 4346 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength()));
4252 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; 4347 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset;
4253 } 4348 }
4254 4349
4255 HEAP_OBJECT_IMPLEMENTATION(Int64Array, ByteArray); 4350 HEAP_OBJECT_IMPLEMENTATION(Int64Array, ByteArray);
4256 friend class ByteArray; 4351 friend class ByteArray;
4257 friend class Class; 4352 friend class Class;
4258 }; 4353 };
4259 4354
4260 4355
4261 class Uint64Array : public ByteArray { 4356 class Uint64Array : public ByteArray {
4262 public: 4357 public:
4263 intptr_t ByteLength() const { 4358 intptr_t ByteLength() const {
4264 return Length() * sizeof(uint64_t); 4359 return Length() * sizeof(uint64_t);
4265 } 4360 }
4266 4361
4267 uint64_t At(intptr_t index) const { 4362 uint64_t At(intptr_t index) const {
4268 ASSERT((index >= 0) && (index < Length())); 4363 ASSERT((index >= 0) && (index < Length()));
4269 return raw_ptr()->data_[index]; 4364 return raw_ptr()->data_[index];
4270 } 4365 }
4271 4366
4272 void SetAt(intptr_t index, uint64_t value) const { 4367 void SetAt(intptr_t index, uint64_t value) const {
4273 ASSERT((index >= 0) && (index < Length())); 4368 ASSERT((index >= 0) && (index < Length()));
4274 raw_ptr()->data_[index] = value; 4369 raw_ptr()->data_[index] = value;
4275 } 4370 }
4276 4371
4372 static const intptr_t kBytesPerElement = 8;
4373 static const intptr_t kMaxElements = MAX_ELEMENTS(Uint64Array);
4374
4277 static intptr_t data_offset() { 4375 static intptr_t data_offset() {
4278 return length_offset() + kWordSize; 4376 return length_offset() + kWordSize;
4279 } 4377 }
4280 4378
4281 static intptr_t InstanceSize() { 4379 static intptr_t InstanceSize() {
4282 ASSERT(sizeof(RawUint64Array) == OFFSET_OF(RawUint64Array, data_)); 4380 ASSERT(sizeof(RawUint64Array) == OFFSET_OF(RawUint64Array, data_));
4283 return 0; 4381 return 0;
4284 } 4382 }
4285 4383
4286 static intptr_t InstanceSize(intptr_t len) { 4384 static intptr_t InstanceSize(intptr_t len) {
4287 intptr_t data_size = len * kBytesPerElement; 4385 ASSERT(0 <= len && len <= kMaxElements);
4288 return RoundedAllocationSize(sizeof(RawUint64Array) + data_size); 4386 return RoundedAllocationSize(
4387 sizeof(RawUint64Array) + (len * kBytesPerElement));
4289 } 4388 }
4290 4389
4291 static RawUint64Array* New(intptr_t len, 4390 static RawUint64Array* New(intptr_t len,
4292 Heap::Space space = Heap::kNew); 4391 Heap::Space space = Heap::kNew);
4293 static RawUint64Array* New(const uint64_t* data, 4392 static RawUint64Array* New(const uint64_t* data,
4294 intptr_t len, 4393 intptr_t len,
4295 Heap::Space space = Heap::kNew); 4394 Heap::Space space = Heap::kNew);
4296 4395
4297 private: 4396 private:
4298 static const intptr_t kBytesPerElement = 8;
4299
4300 uint8_t* ByteAddr(intptr_t byte_offset) const { 4397 uint8_t* ByteAddr(intptr_t byte_offset) const {
4301 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); 4398 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength()));
4302 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; 4399 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset;
4303 } 4400 }
4304 4401
4305 HEAP_OBJECT_IMPLEMENTATION(Uint64Array, ByteArray); 4402 HEAP_OBJECT_IMPLEMENTATION(Uint64Array, ByteArray);
4306 friend class ByteArray; 4403 friend class ByteArray;
4307 friend class Class; 4404 friend class Class;
4308 }; 4405 };
4309 4406
4310 4407
4311 class Float32Array : public ByteArray { 4408 class Float32Array : public ByteArray {
4312 public: 4409 public:
4313 intptr_t ByteLength() const { 4410 intptr_t ByteLength() const {
4314 return Length() * kBytesPerElement; 4411 return Length() * kBytesPerElement;
4315 } 4412 }
4316 4413
4317 float At(intptr_t index) const { 4414 float At(intptr_t index) const {
4318 ASSERT((index >= 0) && (index < Length())); 4415 ASSERT((index >= 0) && (index < Length()));
4319 return raw_ptr()->data_[index]; 4416 return raw_ptr()->data_[index];
4320 } 4417 }
4321 4418
4322 void SetAt(intptr_t index, float value) const { 4419 void SetAt(intptr_t index, float value) const {
4323 ASSERT((index >= 0) && (index < Length())); 4420 ASSERT((index >= 0) && (index < Length()));
4324 raw_ptr()->data_[index] = value; 4421 raw_ptr()->data_[index] = value;
4325 } 4422 }
4326 4423
4424 static const intptr_t kBytesPerElement = 4;
4425 static const intptr_t kMaxElements = MAX_ELEMENTS(Float32Array);
4426
4327 static intptr_t data_offset() { 4427 static intptr_t data_offset() {
4328 return length_offset() + kWordSize; 4428 return length_offset() + kWordSize;
4329 } 4429 }
4330 4430
4331 static intptr_t InstanceSize() { 4431 static intptr_t InstanceSize() {
4332 ASSERT(sizeof(RawFloat32Array) == OFFSET_OF(RawFloat32Array, data_)); 4432 ASSERT(sizeof(RawFloat32Array) == OFFSET_OF(RawFloat32Array, data_));
4333 return 0; 4433 return 0;
4334 } 4434 }
4335 4435
4336 static intptr_t InstanceSize(intptr_t len) { 4436 static intptr_t InstanceSize(intptr_t len) {
4337 intptr_t data_size = len * kBytesPerElement; 4437 ASSERT(0 <= len && len <= kMaxElements);
4338 return RoundedAllocationSize(sizeof(RawFloat32Array) + data_size); 4438 return RoundedAllocationSize(
4439 sizeof(RawFloat32Array) + (len * kBytesPerElement));
4339 } 4440 }
4340 4441
4341 static RawFloat32Array* New(intptr_t len, 4442 static RawFloat32Array* New(intptr_t len,
4342 Heap::Space space = Heap::kNew); 4443 Heap::Space space = Heap::kNew);
4343 static RawFloat32Array* New(const float* data, 4444 static RawFloat32Array* New(const float* data,
4344 intptr_t len, 4445 intptr_t len,
4345 Heap::Space space = Heap::kNew); 4446 Heap::Space space = Heap::kNew);
4346 4447
4347 private: 4448 private:
4348 static const intptr_t kBytesPerElement = 4;
4349
4350 uint8_t* ByteAddr(intptr_t byte_offset) const { 4449 uint8_t* ByteAddr(intptr_t byte_offset) const {
4351 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); 4450 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength()));
4352 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; 4451 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset;
4353 } 4452 }
4354 4453
4355 HEAP_OBJECT_IMPLEMENTATION(Float32Array, ByteArray); 4454 HEAP_OBJECT_IMPLEMENTATION(Float32Array, ByteArray);
4356 friend class ByteArray; 4455 friend class ByteArray;
4357 friend class Class; 4456 friend class Class;
4358 }; 4457 };
4359 4458
4360 4459
4361 class Float64Array : public ByteArray { 4460 class Float64Array : public ByteArray {
4362 public: 4461 public:
4363 intptr_t ByteLength() const { 4462 intptr_t ByteLength() const {
4364 return Length() * kBytesPerElement; 4463 return Length() * kBytesPerElement;
4365 } 4464 }
4366 4465
4367 double At(intptr_t index) const { 4466 double At(intptr_t index) const {
4368 ASSERT((index >= 0) && (index < Length())); 4467 ASSERT((index >= 0) && (index < Length()));
4369 return raw_ptr()->data_[index]; 4468 return raw_ptr()->data_[index];
4370 } 4469 }
4371 4470
4372 void SetAt(intptr_t index, double value) const { 4471 void SetAt(intptr_t index, double value) const {
4373 ASSERT((index >= 0) && (index < Length())); 4472 ASSERT((index >= 0) && (index < Length()));
4374 raw_ptr()->data_[index] = value; 4473 raw_ptr()->data_[index] = value;
4375 } 4474 }
4376 4475
4476 static const intptr_t kBytesPerElement = 8;
4477 static const intptr_t kMaxElements = MAX_ELEMENTS(Float64Array);
4478
4377 static intptr_t InstanceSize() { 4479 static intptr_t InstanceSize() {
4378 ASSERT(sizeof(RawFloat64Array) == OFFSET_OF(RawFloat64Array, data_)); 4480 ASSERT(sizeof(RawFloat64Array) == OFFSET_OF(RawFloat64Array, data_));
4379 return 0; 4481 return 0;
4380 } 4482 }
4381 4483
4382 static intptr_t data_offset() { 4484 static intptr_t data_offset() {
4383 return length_offset() + kWordSize; 4485 return length_offset() + kWordSize;
4384 } 4486 }
4385 4487
4386 static intptr_t InstanceSize(intptr_t len) { 4488 static intptr_t InstanceSize(intptr_t len) {
4387 intptr_t data_size = len * kBytesPerElement; 4489 ASSERT(0 <= len && len <= kMaxElements);
4388 return RoundedAllocationSize(sizeof(RawFloat64Array) + data_size); 4490 return RoundedAllocationSize(
4491 sizeof(RawFloat64Array) + (len * kBytesPerElement));
4389 } 4492 }
4390 4493
4391 static RawFloat64Array* New(intptr_t len, 4494 static RawFloat64Array* New(intptr_t len,
4392 Heap::Space space = Heap::kNew); 4495 Heap::Space space = Heap::kNew);
4393 static RawFloat64Array* New(const double* data, 4496 static RawFloat64Array* New(const double* data,
4394 intptr_t len, 4497 intptr_t len,
4395 Heap::Space space = Heap::kNew); 4498 Heap::Space space = Heap::kNew);
4396 4499
4397 private: 4500 private:
4398 static const intptr_t kBytesPerElement = 8;
4399
4400 uint8_t* ByteAddr(intptr_t byte_offset) const { 4501 uint8_t* ByteAddr(intptr_t byte_offset) const {
4401 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); 4502 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength()));
4402 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; 4503 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset;
4403 } 4504 }
4404 4505
4405 HEAP_OBJECT_IMPLEMENTATION(Float64Array, ByteArray); 4506 HEAP_OBJECT_IMPLEMENTATION(Float64Array, ByteArray);
4406 friend class ByteArray; 4507 friend class ByteArray;
4407 friend class Class; 4508 friend class Class;
4408 }; 4509 };
4409 4510
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
5023 void set_is_multi_line() const { raw_ptr()->flags_ |= kMultiLine; } 5124 void set_is_multi_line() const { raw_ptr()->flags_ |= kMultiLine; }
5024 void set_is_simple() const { raw_ptr()->type_ = kSimple; } 5125 void set_is_simple() const { raw_ptr()->type_ = kSimple; }
5025 void set_is_complex() const { raw_ptr()->type_ = kComplex; } 5126 void set_is_complex() const { raw_ptr()->type_ = kComplex; }
5026 5127
5027 void* GetDataStartAddress() const; 5128 void* GetDataStartAddress() const;
5028 static RawJSRegExp* FromDataStartAddress(void* data); 5129 static RawJSRegExp* FromDataStartAddress(void* data);
5029 const char* Flags() const; 5130 const char* Flags() const;
5030 5131
5031 virtual bool Equals(const Instance& other) const; 5132 virtual bool Equals(const Instance& other) const;
5032 5133
5134 static const intptr_t kBytesPerElement = 1;
5135 static const intptr_t kMaxElements = MAX_ELEMENTS(JSRegExp);
5136
5033 static intptr_t InstanceSize() { 5137 static intptr_t InstanceSize() {
5034 ASSERT(sizeof(RawJSRegExp) == OFFSET_OF(RawJSRegExp, data_)); 5138 ASSERT(sizeof(RawJSRegExp) == OFFSET_OF(RawJSRegExp, data_));
5035 return 0; 5139 return 0;
5036 } 5140 }
5037 5141
5038 static intptr_t InstanceSize(intptr_t len) { 5142 static intptr_t InstanceSize(intptr_t len) {
5039 return RoundedAllocationSize(sizeof(RawJSRegExp) + len); 5143 ASSERT(0 <= len && len <= kMaxElements);
5144 return RoundedAllocationSize(
5145 sizeof(RawJSRegExp) + (len * kBytesPerElement));
5040 } 5146 }
5041 5147
5042 static RawJSRegExp* New(intptr_t length, Heap::Space space = Heap::kNew); 5148 static RawJSRegExp* New(intptr_t length, Heap::Space space = Heap::kNew);
5043 5149
5044 private: 5150 private:
5045 void set_type(RegExType type) const { raw_ptr()->type_ = type; } 5151 void set_type(RegExType type) const { raw_ptr()->type_ = type; }
5046 void set_flags(intptr_t value) const { raw_ptr()->flags_ = value; } 5152 void set_flags(intptr_t value) const { raw_ptr()->flags_ = value; }
5047 5153
5048 void SetLength(intptr_t value) const { 5154 void SetLength(intptr_t value) const {
5049 // This is only safe because we create a new Smi, which does not cause 5155 // This is only safe because we create a new Smi, which does not cause
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
5130 } 5236 }
5131 5237
5132 5238
5133 intptr_t Stackmap::SizeInBits() const { 5239 intptr_t Stackmap::SizeInBits() const {
5134 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); 5240 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte);
5135 } 5241 }
5136 5242
5137 } // namespace dart 5243 } // namespace dart
5138 5244
5139 #endif // VM_OBJECT_H_ 5245 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698