| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #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 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const; | 1234 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const; |
| 1235 virtual bool IsResolved() const; | 1235 virtual bool IsResolved() const; |
| 1236 virtual bool IsInstantiated() const; | 1236 virtual bool IsInstantiated() const; |
| 1237 virtual bool IsUninstantiatedIdentity() const; | 1237 virtual bool IsUninstantiatedIdentity() const; |
| 1238 // Canonicalize only if instantiated, otherwise returns 'this'. | 1238 // Canonicalize only if instantiated, otherwise returns 'this'. |
| 1239 virtual RawAbstractTypeArguments* Canonicalize() const; | 1239 virtual RawAbstractTypeArguments* Canonicalize() const; |
| 1240 | 1240 |
| 1241 virtual RawAbstractTypeArguments* InstantiateFrom( | 1241 virtual RawAbstractTypeArguments* InstantiateFrom( |
| 1242 const AbstractTypeArguments& instantiator_type_arguments) const; | 1242 const AbstractTypeArguments& instantiator_type_arguments) const; |
| 1243 | 1243 |
| 1244 static const intptr_t kBytesPerElement = kWordSize; |
| 1245 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 1246 |
| 1244 static intptr_t length_offset() { | 1247 static intptr_t length_offset() { |
| 1245 return OFFSET_OF(RawTypeArguments, length_); | 1248 return OFFSET_OF(RawTypeArguments, length_); |
| 1246 } | 1249 } |
| 1247 | 1250 |
| 1248 static intptr_t InstanceSize() { | 1251 static intptr_t InstanceSize() { |
| 1249 ASSERT(sizeof(RawTypeArguments) == OFFSET_OF(RawTypeArguments, types_)); | 1252 ASSERT(sizeof(RawTypeArguments) == OFFSET_OF(RawTypeArguments, types_)); |
| 1250 return 0; | 1253 return 0; |
| 1251 } | 1254 } |
| 1252 | 1255 |
| 1253 static intptr_t InstanceSize(intptr_t len) { | 1256 static intptr_t InstanceSize(intptr_t len) { |
| 1254 // Ensure that the types_ is not adding to the object length. | 1257 // Ensure that the types_ is not adding to the object length. |
| 1255 ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (1 * kWordSize))); | 1258 ASSERT(sizeof(RawTypeArguments) == (sizeof(RawObject) + (1 * kWordSize))); |
| 1256 return RoundedAllocationSize(sizeof(RawTypeArguments) + (len * kWordSize)); | 1259 ASSERT(0 <= len && len <= kMaxElements); |
| 1260 return RoundedAllocationSize( |
| 1261 sizeof(RawTypeArguments) + (len * kBytesPerElement)); |
| 1257 } | 1262 } |
| 1258 | 1263 |
| 1259 static RawTypeArguments* New(intptr_t len, Heap::Space space = Heap::kOld); | 1264 static RawTypeArguments* New(intptr_t len, Heap::Space space = Heap::kOld); |
| 1260 | 1265 |
| 1261 private: | 1266 private: |
| 1262 // Make sure that the array size cannot wrap around. | |
| 1263 static const intptr_t kMaxTypes = 512 * 1024 * 1024; | |
| 1264 RawAbstractType** TypeAddr(intptr_t index) const; | 1267 RawAbstractType** TypeAddr(intptr_t index) const; |
| 1265 void SetLength(intptr_t value) const; | 1268 void SetLength(intptr_t value) const; |
| 1266 | 1269 |
| 1267 HEAP_OBJECT_IMPLEMENTATION(TypeArguments, AbstractTypeArguments); | 1270 HEAP_OBJECT_IMPLEMENTATION(TypeArguments, AbstractTypeArguments); |
| 1268 friend class Class; | 1271 friend class Class; |
| 1269 }; | 1272 }; |
| 1270 | 1273 |
| 1271 | 1274 |
| 1272 // An instance of InstantiatedTypeArguments is never encountered at compile | 1275 // An instance of InstantiatedTypeArguments is never encountered at compile |
| 1273 // time, but only at run time, when type parameters can be matched to actual | 1276 // time, but only at run time, when type parameters can be matched to actual |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1751 public: | 1754 public: |
| 1752 inline intptr_t Length() const; | 1755 inline intptr_t Length() const; |
| 1753 | 1756 |
| 1754 RawArray* TokenObjects() const; | 1757 RawArray* TokenObjects() const; |
| 1755 void SetTokenObjects(const Array& value) const; | 1758 void SetTokenObjects(const Array& value) const; |
| 1756 | 1759 |
| 1757 RawString* GenerateSource() const; | 1760 RawString* GenerateSource() const; |
| 1758 intptr_t ComputeSourcePosition(intptr_t tok_pos) const; | 1761 intptr_t ComputeSourcePosition(intptr_t tok_pos) const; |
| 1759 intptr_t ComputeTokenPosition(intptr_t src_pos) const; | 1762 intptr_t ComputeTokenPosition(intptr_t src_pos) const; |
| 1760 | 1763 |
| 1764 static const intptr_t kBytesPerElement = 1; |
| 1765 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 1766 |
| 1761 static intptr_t InstanceSize() { | 1767 static intptr_t InstanceSize() { |
| 1762 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_)); | 1768 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_)); |
| 1763 return 0; | 1769 return 0; |
| 1764 } | 1770 } |
| 1765 static intptr_t InstanceSize(intptr_t len) { | 1771 static intptr_t InstanceSize(intptr_t len) { |
| 1766 return RoundedAllocationSize(sizeof(RawTokenStream) + len); | 1772 ASSERT(0 <= len && len <= kMaxElements); |
| 1773 return RoundedAllocationSize( |
| 1774 sizeof(RawTokenStream) + (len * kBytesPerElement)); |
| 1767 } | 1775 } |
| 1768 | 1776 |
| 1769 static RawTokenStream* New(intptr_t length); | 1777 static RawTokenStream* New(intptr_t length); |
| 1770 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens); | 1778 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens); |
| 1771 | 1779 |
| 1772 // The class Iterator encapsulates iteration over the tokens | 1780 // The class Iterator encapsulates iteration over the tokens |
| 1773 // in a TokenStream object. | 1781 // in a TokenStream object. |
| 1774 class Iterator : ValueObject { | 1782 class Iterator : ValueObject { |
| 1775 public: | 1783 public: |
| 1776 Iterator(const TokenStream& tokens, intptr_t token_pos); | 1784 Iterator(const TokenStream& tokens, intptr_t token_pos); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2091 | 2099 |
| 2092 class Instructions : public Object { | 2100 class Instructions : public Object { |
| 2093 public: | 2101 public: |
| 2094 intptr_t size() const { return raw_ptr()->size_; } | 2102 intptr_t size() const { return raw_ptr()->size_; } |
| 2095 RawCode* code() const { return raw_ptr()->code_; } | 2103 RawCode* code() const { return raw_ptr()->code_; } |
| 2096 | 2104 |
| 2097 uword EntryPoint() const { | 2105 uword EntryPoint() const { |
| 2098 return reinterpret_cast<uword>(raw_ptr()) + HeaderSize(); | 2106 return reinterpret_cast<uword>(raw_ptr()) + HeaderSize(); |
| 2099 } | 2107 } |
| 2100 | 2108 |
| 2109 static const intptr_t kMaxElements = (kIntptrMax - |
| 2110 (sizeof(RawInstructions) + |
| 2111 sizeof(RawObject) + |
| 2112 (2 * OS::kMaxPreferredCodeAlignment))); |
| 2113 |
| 2101 static intptr_t InstanceSize() { | 2114 static intptr_t InstanceSize() { |
| 2102 ASSERT(sizeof(RawInstructions) == OFFSET_OF(RawInstructions, data_)); | 2115 ASSERT(sizeof(RawInstructions) == OFFSET_OF(RawInstructions, data_)); |
| 2103 return 0; | 2116 return 0; |
| 2104 } | 2117 } |
| 2105 | 2118 |
| 2106 static intptr_t InstanceSize(intptr_t size) { | 2119 static intptr_t InstanceSize(intptr_t size) { |
| 2107 intptr_t instructions_size = Utils::RoundUp(size, | 2120 intptr_t instructions_size = Utils::RoundUp(size, |
| 2108 OS::PreferredCodeAlignment()); | 2121 OS::PreferredCodeAlignment()); |
| 2109 intptr_t result = instructions_size + HeaderSize(); | 2122 intptr_t result = instructions_size + HeaderSize(); |
| 2110 ASSERT(result % OS::PreferredCodeAlignment() == 0); | 2123 ASSERT(result % OS::PreferredCodeAlignment() == 0); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2146 intptr_t Length() const; | 2159 intptr_t Length() const; |
| 2147 | 2160 |
| 2148 RawString* GetName(intptr_t var_index) const; | 2161 RawString* GetName(intptr_t var_index) const; |
| 2149 | 2162 |
| 2150 void SetVar(intptr_t var_index, | 2163 void SetVar(intptr_t var_index, |
| 2151 const String& name, | 2164 const String& name, |
| 2152 RawLocalVarDescriptors::VarInfo* info) const; | 2165 RawLocalVarDescriptors::VarInfo* info) const; |
| 2153 | 2166 |
| 2154 void GetInfo(intptr_t var_index, RawLocalVarDescriptors::VarInfo* info) const; | 2167 void GetInfo(intptr_t var_index, RawLocalVarDescriptors::VarInfo* info) const; |
| 2155 | 2168 |
| 2169 static const intptr_t kBytesPerElement = |
| 2170 sizeof(RawLocalVarDescriptors::VarInfo); |
| 2171 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 2172 |
| 2156 static intptr_t InstanceSize() { | 2173 static intptr_t InstanceSize() { |
| 2157 ASSERT(sizeof(RawLocalVarDescriptors) == | 2174 ASSERT(sizeof(RawLocalVarDescriptors) == |
| 2158 OFFSET_OF(RawLocalVarDescriptors, data_)); | 2175 OFFSET_OF(RawLocalVarDescriptors, data_)); |
| 2159 return 0; | 2176 return 0; |
| 2160 } | 2177 } |
| 2161 static intptr_t InstanceSize(intptr_t len) { | 2178 static intptr_t InstanceSize(intptr_t len) { |
| 2179 ASSERT(0 <= len && len <= kMaxElements); |
| 2162 return RoundedAllocationSize( | 2180 return RoundedAllocationSize( |
| 2163 sizeof(RawLocalVarDescriptors) + | 2181 sizeof(RawLocalVarDescriptors) + (len * kBytesPerElement)); |
| 2164 (len * sizeof(RawLocalVarDescriptors::VarInfo))); | |
| 2165 } | 2182 } |
| 2166 | 2183 |
| 2167 static RawLocalVarDescriptors* New(intptr_t num_variables); | 2184 static RawLocalVarDescriptors* New(intptr_t num_variables); |
| 2168 | 2185 |
| 2169 private: | 2186 private: |
| 2170 HEAP_OBJECT_IMPLEMENTATION(LocalVarDescriptors, Object); | 2187 HEAP_OBJECT_IMPLEMENTATION(LocalVarDescriptors, Object); |
| 2171 friend class Class; | 2188 friend class Class; |
| 2172 }; | 2189 }; |
| 2173 | 2190 |
| 2174 | 2191 |
| 2175 class PcDescriptors : public Object { | 2192 class PcDescriptors : public Object { |
| 2193 private: |
| 2194 // Describes the layout of PC descriptor data. |
| 2195 enum { |
| 2196 kPcEntry = 0, // PC value of the descriptor, unique. |
| 2197 kKindEntry, |
| 2198 kNodeIdEntry, // AST node id. |
| 2199 kTokenIndexEntry, // Token position in source of PC. |
| 2200 kTryIndexEntry, // Try block index of PC. |
| 2201 // We would potentially be adding other objects here like |
| 2202 // pointer maps for optimized functions, local variables information etc. |
| 2203 kNumberOfEntries |
| 2204 }; |
| 2205 |
| 2176 public: | 2206 public: |
| 2177 enum Kind { | 2207 enum Kind { |
| 2178 kDeopt = 0, // Deoptimization cotinuation point. | 2208 kDeopt = 0, // Deoptimization cotinuation point. |
| 2179 kPatchCode, // Buffer for patching code entry. | 2209 kPatchCode, // Buffer for patching code entry. |
| 2180 kIcCall, // IC call. | 2210 kIcCall, // IC call. |
| 2181 kFuncCall, // Call to known target, e.g. static call, closure call. | 2211 kFuncCall, // Call to known target, e.g. static call, closure call. |
| 2182 kReturn, // Return from function. | 2212 kReturn, // Return from function. |
| 2183 kOther | 2213 kOther |
| 2184 }; | 2214 }; |
| 2185 | 2215 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2198 intptr_t node_id, | 2228 intptr_t node_id, |
| 2199 intptr_t token_pos, | 2229 intptr_t token_pos, |
| 2200 intptr_t try_index) const { | 2230 intptr_t try_index) const { |
| 2201 SetPC(index, pc); | 2231 SetPC(index, pc); |
| 2202 SetKind(index, kind); | 2232 SetKind(index, kind); |
| 2203 SetNodeId(index, node_id); | 2233 SetNodeId(index, node_id); |
| 2204 SetTokenIndex(index, token_pos); | 2234 SetTokenIndex(index, token_pos); |
| 2205 SetTryIndex(index, try_index); | 2235 SetTryIndex(index, try_index); |
| 2206 } | 2236 } |
| 2207 | 2237 |
| 2238 static const intptr_t kBytesPerElement = (kNumberOfEntries * kWordSize); |
| 2239 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 2240 |
| 2208 static intptr_t InstanceSize() { | 2241 static intptr_t InstanceSize() { |
| 2209 ASSERT(sizeof(RawPcDescriptors) == OFFSET_OF(RawPcDescriptors, data_)); | 2242 ASSERT(sizeof(RawPcDescriptors) == OFFSET_OF(RawPcDescriptors, data_)); |
| 2210 return 0; | 2243 return 0; |
| 2211 } | 2244 } |
| 2212 static intptr_t InstanceSize(intptr_t len) { | 2245 static intptr_t InstanceSize(intptr_t len) { |
| 2246 ASSERT(0 <= len && len <= kMaxElements); |
| 2213 return RoundedAllocationSize( | 2247 return RoundedAllocationSize( |
| 2214 sizeof(RawPcDescriptors) + (len * kNumberOfEntries * kWordSize)); | 2248 sizeof(RawPcDescriptors) + (len * kBytesPerElement)); |
| 2215 } | 2249 } |
| 2216 | 2250 |
| 2217 static RawPcDescriptors* New(intptr_t num_descriptors); | 2251 static RawPcDescriptors* New(intptr_t num_descriptors); |
| 2218 | 2252 |
| 2219 // Verify (assert) assumptions about pc descriptors in debug mode. | 2253 // Verify (assert) assumptions about pc descriptors in debug mode. |
| 2220 void Verify(bool check_ids) const; | 2254 void Verify(bool check_ids) const; |
| 2221 | 2255 |
| 2222 // We would have a VisitPointers function here to traverse the | 2256 // We would have a VisitPointers function here to traverse the |
| 2223 // pc descriptors table to visit objects if any in the table. | 2257 // pc descriptors table to visit objects if any in the table. |
| 2224 | 2258 |
| 2225 private: | 2259 private: |
| 2226 // Describes the layout of PC descriptor data. | |
| 2227 enum { | |
| 2228 kPcEntry = 0, // PC value of the descriptor, unique. | |
| 2229 kKindEntry, | |
| 2230 kNodeIdEntry, // AST node id. | |
| 2231 kTokenIndexEntry, // Token position in source of PC. | |
| 2232 kTryIndexEntry, // Try block index of PC. | |
| 2233 // We would potentially be adding other objects here like | |
| 2234 // pointer maps for optimized functions, local variables information etc. | |
| 2235 kNumberOfEntries | |
| 2236 }; | |
| 2237 | |
| 2238 void SetPC(intptr_t index, uword value) const; | 2260 void SetPC(intptr_t index, uword value) const; |
| 2239 void SetKind(intptr_t index, PcDescriptors::Kind kind) const; | 2261 void SetKind(intptr_t index, PcDescriptors::Kind kind) const; |
| 2240 void SetNodeId(intptr_t index, intptr_t value) const; | 2262 void SetNodeId(intptr_t index, intptr_t value) const; |
| 2241 void SetTokenIndex(intptr_t index, intptr_t value) const; | 2263 void SetTokenIndex(intptr_t index, intptr_t value) const; |
| 2242 void SetTryIndex(intptr_t index, intptr_t value) const; | 2264 void SetTryIndex(intptr_t index, intptr_t value) const; |
| 2243 | 2265 |
| 2244 void SetLength(intptr_t value) const; | 2266 void SetLength(intptr_t value) const; |
| 2245 | 2267 |
| 2246 intptr_t* EntryAddr(intptr_t index, intptr_t entry_offset) const { | 2268 intptr_t* EntryAddr(intptr_t index, intptr_t entry_offset) const { |
| 2247 ASSERT((index >=0) && (index < Length())); | 2269 ASSERT((index >=0) && (index < Length())); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2270 | 2292 |
| 2271 RawCode* GetCode() const { return raw_ptr()->code_; } | 2293 RawCode* GetCode() const { return raw_ptr()->code_; } |
| 2272 void SetCode(const Code& code) const; | 2294 void SetCode(const Code& code) const; |
| 2273 | 2295 |
| 2274 // Return the index of the highest stack slot that has an object. | 2296 // Return the index of the highest stack slot that has an object. |
| 2275 intptr_t MaximumBitIndex() const { return raw_ptr()->max_set_bit_index_; } | 2297 intptr_t MaximumBitIndex() const { return raw_ptr()->max_set_bit_index_; } |
| 2276 | 2298 |
| 2277 // Return the index of the lowest stack slot that has an object. | 2299 // Return the index of the lowest stack slot that has an object. |
| 2278 intptr_t MinimumBitIndex() const { return raw_ptr()->min_set_bit_index_; } | 2300 intptr_t MinimumBitIndex() const { return raw_ptr()->min_set_bit_index_; } |
| 2279 | 2301 |
| 2302 static const intptr_t kBytesPerElement = kWordSize; |
| 2303 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 2304 |
| 2280 static intptr_t InstanceSize() { | 2305 static intptr_t InstanceSize() { |
| 2281 ASSERT(sizeof(RawStackmap) == OFFSET_OF(RawStackmap, data_)); | 2306 ASSERT(sizeof(RawStackmap) == OFFSET_OF(RawStackmap, data_)); |
| 2282 return 0; | 2307 return 0; |
| 2283 } | 2308 } |
| 2284 static intptr_t InstanceSize(intptr_t size) { | 2309 static intptr_t InstanceSize(intptr_t len) { |
| 2285 return RoundedAllocationSize(sizeof(RawStackmap) + (size * kWordSize)); | 2310 ASSERT(0 <= len && len <= kMaxElements); |
| 2311 return RoundedAllocationSize( |
| 2312 sizeof(RawStackmap) + (len * kBytesPerElement)); |
| 2286 } | 2313 } |
| 2287 static RawStackmap* New(uword pc, BitmapBuilder* bmap); | 2314 static RawStackmap* New(uword pc, BitmapBuilder* bmap); |
| 2288 | 2315 |
| 2289 private: | 2316 private: |
| 2290 inline intptr_t SizeInBits() const; | 2317 inline intptr_t SizeInBits() const; |
| 2291 | 2318 |
| 2292 void SetMinBitIndex(intptr_t value) const { | 2319 void SetMinBitIndex(intptr_t value) const { |
| 2293 raw_ptr()->min_set_bit_index_ = value; | 2320 raw_ptr()->min_set_bit_index_ = value; |
| 2294 } | 2321 } |
| 2295 void SetMaxBitIndex(intptr_t value) const { | 2322 void SetMaxBitIndex(intptr_t value) const { |
| 2296 raw_ptr()->max_set_bit_index_ = value; | 2323 raw_ptr()->max_set_bit_index_ = value; |
| 2297 } | 2324 } |
| 2298 | 2325 |
| 2299 bool InRange(intptr_t index) const { return index < SizeInBits(); } | 2326 bool InRange(intptr_t index) const { return index < SizeInBits(); } |
| 2300 | 2327 |
| 2301 bool GetBit(intptr_t bit_index) const; | 2328 bool GetBit(intptr_t bit_index) const; |
| 2302 void SetBit(intptr_t bit_index, bool value) const; | 2329 void SetBit(intptr_t bit_index, bool value) const; |
| 2303 | 2330 |
| 2304 void set_bitmap_size_in_bytes(intptr_t value) const; | 2331 void set_bitmap_size_in_bytes(intptr_t value) const; |
| 2305 | 2332 |
| 2306 HEAP_OBJECT_IMPLEMENTATION(Stackmap, Object); | 2333 HEAP_OBJECT_IMPLEMENTATION(Stackmap, Object); |
| 2307 friend class BitmapBuilder; | 2334 friend class BitmapBuilder; |
| 2308 friend class Class; | 2335 friend class Class; |
| 2309 }; | 2336 }; |
| 2310 | 2337 |
| 2311 | 2338 |
| 2312 class ExceptionHandlers : public Object { | 2339 class ExceptionHandlers : public Object { |
| 2340 private: |
| 2341 // Describes the layout of exception handler data. |
| 2342 enum { |
| 2343 kTryIndexEntry = 0, // Try block index associated with handler. |
| 2344 kHandlerPcEntry, // PC value of handler. |
| 2345 kNumberOfEntries |
| 2346 }; |
| 2347 |
| 2313 public: | 2348 public: |
| 2314 intptr_t Length() const; | 2349 intptr_t Length() const; |
| 2315 | 2350 |
| 2316 intptr_t TryIndex(intptr_t index) const; | 2351 intptr_t TryIndex(intptr_t index) const; |
| 2317 intptr_t HandlerPC(intptr_t index) const; | 2352 intptr_t HandlerPC(intptr_t index) const; |
| 2318 | 2353 |
| 2319 void SetHandlerEntry(intptr_t index, | 2354 void SetHandlerEntry(intptr_t index, |
| 2320 intptr_t try_index, | 2355 intptr_t try_index, |
| 2321 intptr_t handler_pc) const { | 2356 intptr_t handler_pc) const { |
| 2322 SetTryIndex(index, try_index); | 2357 SetTryIndex(index, try_index); |
| 2323 SetHandlerPC(index, handler_pc); | 2358 SetHandlerPC(index, handler_pc); |
| 2324 } | 2359 } |
| 2325 | 2360 |
| 2361 static const intptr_t kBytesPerElement = (kNumberOfEntries * kWordSize); |
| 2362 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 2363 |
| 2326 static intptr_t InstanceSize() { | 2364 static intptr_t InstanceSize() { |
| 2327 ASSERT(sizeof(RawExceptionHandlers) == OFFSET_OF(RawExceptionHandlers, | 2365 ASSERT(sizeof(RawExceptionHandlers) == OFFSET_OF(RawExceptionHandlers, |
| 2328 data_)); | 2366 data_)); |
| 2329 return 0; | 2367 return 0; |
| 2330 } | 2368 } |
| 2331 static intptr_t InstanceSize(intptr_t len) { | 2369 static intptr_t InstanceSize(intptr_t len) { |
| 2332 return RoundedAllocationSize(sizeof(RawExceptionHandlers) + | 2370 ASSERT(0 <= len && len <= kMaxElements); |
| 2333 (len * kNumberOfEntries * kWordSize)); | 2371 return RoundedAllocationSize( |
| 2372 sizeof(RawExceptionHandlers) + (len * kBytesPerElement)); |
| 2334 } | 2373 } |
| 2335 | 2374 |
| 2336 static RawExceptionHandlers* New(intptr_t num_handlers); | 2375 static RawExceptionHandlers* New(intptr_t num_handlers); |
| 2337 | 2376 |
| 2338 // We would have a VisitPointers function here to traverse the | 2377 // We would have a VisitPointers function here to traverse the |
| 2339 // exception handler table to visit objects if any in the table. | 2378 // exception handler table to visit objects if any in the table. |
| 2340 | 2379 |
| 2341 private: | 2380 private: |
| 2342 // Describes the layout of exception handler data. | |
| 2343 enum { | |
| 2344 kTryIndexEntry = 0, // Try block index associated with handler. | |
| 2345 kHandlerPcEntry, // PC value of handler. | |
| 2346 kNumberOfEntries | |
| 2347 }; | |
| 2348 | |
| 2349 void SetTryIndex(intptr_t index, intptr_t value) const; | 2381 void SetTryIndex(intptr_t index, intptr_t value) const; |
| 2350 void SetHandlerPC(intptr_t index, intptr_t value) const; | 2382 void SetHandlerPC(intptr_t index, intptr_t value) const; |
| 2351 | 2383 |
| 2352 void SetLength(intptr_t value) const; | 2384 void SetLength(intptr_t value) const; |
| 2353 | 2385 |
| 2354 intptr_t* EntryAddr(intptr_t index, intptr_t entry_offset) const { | 2386 intptr_t* EntryAddr(intptr_t index, intptr_t entry_offset) const { |
| 2355 ASSERT((index >=0) && (index < Length())); | 2387 ASSERT((index >=0) && (index < Length())); |
| 2356 intptr_t data_index = (index * kNumberOfEntries) + entry_offset; | 2388 intptr_t data_index = (index * kNumberOfEntries) + entry_offset; |
| 2357 return &raw_ptr()->data_[data_index]; | 2389 return &raw_ptr()->data_[data_index]; |
| 2358 } | 2390 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2449 RawFunction* function() const { | 2481 RawFunction* function() const { |
| 2450 return raw_ptr()->function_; | 2482 return raw_ptr()->function_; |
| 2451 } | 2483 } |
| 2452 void set_function(const Function& function) const { | 2484 void set_function(const Function& function) const { |
| 2453 StorePointer(&raw_ptr()->function_, function.raw()); | 2485 StorePointer(&raw_ptr()->function_, function.raw()); |
| 2454 } | 2486 } |
| 2455 | 2487 |
| 2456 // We would have a VisitPointers function here to traverse all the | 2488 // We would have a VisitPointers function here to traverse all the |
| 2457 // embedded objects in the instructions using pointer_offsets. | 2489 // embedded objects in the instructions using pointer_offsets. |
| 2458 | 2490 |
| 2491 static const intptr_t kBytesPerElement = |
| 2492 sizeof(reinterpret_cast<RawCode*>(0)->data_[0]); |
| 2493 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 2494 |
| 2459 static intptr_t InstanceSize() { | 2495 static intptr_t InstanceSize() { |
| 2460 ASSERT(sizeof(RawCode) == OFFSET_OF(RawCode, data_)); | 2496 ASSERT(sizeof(RawCode) == OFFSET_OF(RawCode, data_)); |
| 2461 return 0; | 2497 return 0; |
| 2462 } | 2498 } |
| 2463 static intptr_t InstanceSize(intptr_t pointer_offsets_length) { | 2499 static intptr_t InstanceSize(intptr_t len) { |
| 2464 return RoundedAllocationSize( | 2500 ASSERT(0 <= len && len <= kMaxElements); |
| 2465 sizeof(RawCode) + (pointer_offsets_length * kEntrySize)); | 2501 return RoundedAllocationSize(sizeof(RawCode) + (len * kBytesPerElement)); |
| 2466 } | 2502 } |
| 2467 static RawCode* FinalizeCode(const Function& function, Assembler* assembler); | 2503 static RawCode* FinalizeCode(const Function& function, Assembler* assembler); |
| 2468 static RawCode* FinalizeCode(const char* name, Assembler* assembler); | 2504 static RawCode* FinalizeCode(const char* name, Assembler* assembler); |
| 2469 static RawCode* LookupCode(uword pc); | 2505 static RawCode* LookupCode(uword pc); |
| 2470 | 2506 |
| 2471 int32_t GetPointerOffsetAt(int index) const { | 2507 int32_t GetPointerOffsetAt(int index) const { |
| 2472 return *PointerOffsetAddrAt(index); | 2508 return *PointerOffsetAddrAt(index); |
| 2473 } | 2509 } |
| 2474 intptr_t GetTokenIndexOfPC(uword pc) const; | 2510 intptr_t GetTokenIndexOfPC(uword pc) const; |
| 2475 | 2511 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2522 return &raw_ptr()->data_[index]; | 2558 return &raw_ptr()->data_[index]; |
| 2523 } | 2559 } |
| 2524 void SetPointerOffsetAt(int index, int32_t offset_in_instructions) { | 2560 void SetPointerOffsetAt(int index, int32_t offset_in_instructions) { |
| 2525 *PointerOffsetAddrAt(index) = offset_in_instructions; | 2561 *PointerOffsetAddrAt(index) = offset_in_instructions; |
| 2526 } | 2562 } |
| 2527 | 2563 |
| 2528 // New is a private method as RawInstruction and RawCode objects should | 2564 // New is a private method as RawInstruction and RawCode objects should |
| 2529 // only be created using the Code::FinalizeCode method. This method creates | 2565 // only be created using the Code::FinalizeCode method. This method creates |
| 2530 // the RawInstruction and RawCode objects, sets up the pointer offsets | 2566 // the RawInstruction and RawCode objects, sets up the pointer offsets |
| 2531 // and links the two in a GC safe manner. | 2567 // and links the two in a GC safe manner. |
| 2532 static RawCode* New(int pointer_offsets_length); | 2568 static RawCode* New(intptr_t pointer_offsets_length); |
| 2533 | 2569 |
| 2534 HEAP_OBJECT_IMPLEMENTATION(Code, Object); | 2570 HEAP_OBJECT_IMPLEMENTATION(Code, Object); |
| 2535 friend class Class; | 2571 friend class Class; |
| 2536 }; | 2572 }; |
| 2537 | 2573 |
| 2538 | 2574 |
| 2539 class Context : public Object { | 2575 class Context : public Object { |
| 2540 public: | 2576 public: |
| 2541 RawContext* parent() const { return raw_ptr()->parent_; } | 2577 RawContext* parent() const { return raw_ptr()->parent_; } |
| 2542 void set_parent(const Context& parent) const { | 2578 void set_parent(const Context& parent) const { |
| 2543 ASSERT(parent.IsNull() || parent.isolate() == Isolate::Current()); | 2579 ASSERT(parent.IsNull() || parent.isolate() == Isolate::Current()); |
| 2544 StorePointer(&raw_ptr()->parent_, parent.raw()); | 2580 StorePointer(&raw_ptr()->parent_, parent.raw()); |
| 2545 } | 2581 } |
| 2546 static intptr_t parent_offset() { return OFFSET_OF(RawContext, parent_); } | 2582 static intptr_t parent_offset() { return OFFSET_OF(RawContext, parent_); } |
| 2547 | 2583 |
| 2548 Isolate* isolate() const { return raw_ptr()->isolate_; } | 2584 Isolate* isolate() const { return raw_ptr()->isolate_; } |
| 2549 static intptr_t isolate_offset() { return OFFSET_OF(RawContext, isolate_); } | 2585 static intptr_t isolate_offset() { return OFFSET_OF(RawContext, isolate_); } |
| 2550 | 2586 |
| 2551 intptr_t num_variables() const { return raw_ptr()->num_variables_; } | 2587 intptr_t num_variables() const { return raw_ptr()->num_variables_; } |
| 2552 static intptr_t num_variables_offset() { | 2588 static intptr_t num_variables_offset() { |
| 2553 return OFFSET_OF(RawContext, num_variables_); | 2589 return OFFSET_OF(RawContext, num_variables_); |
| 2554 } | 2590 } |
| 2555 | 2591 |
| 2556 RawInstance* At(intptr_t context_index) const { | 2592 RawInstance* At(intptr_t context_index) const { |
| 2557 return *InstanceAddr(context_index); | 2593 return *InstanceAddr(context_index); |
| 2558 } | 2594 } |
| 2559 inline void SetAt(intptr_t context_index, const Instance& value) const; | 2595 inline void SetAt(intptr_t context_index, const Instance& value) const; |
| 2560 | 2596 |
| 2597 static const intptr_t kBytesPerElement = kWordSize; |
| 2598 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 2599 |
| 2561 static intptr_t variable_offset(intptr_t context_index) { | 2600 static intptr_t variable_offset(intptr_t context_index) { |
| 2562 return OFFSET_OF(RawContext, data_[context_index]); | 2601 return OFFSET_OF(RawContext, data_[context_index]); |
| 2563 } | 2602 } |
| 2564 | 2603 |
| 2565 static intptr_t InstanceSize() { | 2604 static intptr_t InstanceSize() { |
| 2566 ASSERT(sizeof(RawContext) == OFFSET_OF(RawContext, data_)); | 2605 ASSERT(sizeof(RawContext) == OFFSET_OF(RawContext, data_)); |
| 2567 return 0; | 2606 return 0; |
| 2568 } | 2607 } |
| 2569 | 2608 |
| 2570 static intptr_t InstanceSize(intptr_t num_variables) { | 2609 static intptr_t InstanceSize(intptr_t len) { |
| 2571 return RoundedAllocationSize(sizeof(RawContext) + | 2610 ASSERT(0 <= len && len <= kMaxElements); |
| 2572 (num_variables * kWordSize)); | 2611 return RoundedAllocationSize(sizeof(RawContext) + (len * kBytesPerElement)); |
| 2573 } | 2612 } |
| 2574 | 2613 |
| 2575 static RawContext* New(intptr_t num_variables, | 2614 static RawContext* New(intptr_t num_variables, |
| 2576 Heap::Space space = Heap::kNew); | 2615 Heap::Space space = Heap::kNew); |
| 2577 | 2616 |
| 2578 private: | 2617 private: |
| 2579 RawInstance** InstanceAddr(intptr_t context_index) const { | 2618 RawInstance** InstanceAddr(intptr_t context_index) const { |
| 2580 ASSERT((context_index >= 0) && (context_index < num_variables())); | 2619 ASSERT((context_index >= 0) && (context_index < num_variables())); |
| 2581 return &raw_ptr()->data_[context_index]; | 2620 return &raw_ptr()->data_[context_index]; |
| 2582 } | 2621 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2618 | 2657 |
| 2619 RawAbstractType* TypeAt(intptr_t scope_index) const; | 2658 RawAbstractType* TypeAt(intptr_t scope_index) const; |
| 2620 void SetTypeAt(intptr_t scope_index, const AbstractType& type) const; | 2659 void SetTypeAt(intptr_t scope_index, const AbstractType& type) const; |
| 2621 | 2660 |
| 2622 intptr_t ContextIndexAt(intptr_t scope_index) const; | 2661 intptr_t ContextIndexAt(intptr_t scope_index) const; |
| 2623 void SetContextIndexAt(intptr_t scope_index, intptr_t context_index) const; | 2662 void SetContextIndexAt(intptr_t scope_index, intptr_t context_index) const; |
| 2624 | 2663 |
| 2625 intptr_t ContextLevelAt(intptr_t scope_index) const; | 2664 intptr_t ContextLevelAt(intptr_t scope_index) const; |
| 2626 void SetContextLevelAt(intptr_t scope_index, intptr_t context_level) const; | 2665 void SetContextLevelAt(intptr_t scope_index, intptr_t context_level) const; |
| 2627 | 2666 |
| 2667 static const intptr_t kBytesPerElement = |
| 2668 sizeof(RawContextScope::VariableDesc); |
| 2669 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 2670 |
| 2628 static intptr_t InstanceSize() { | 2671 static intptr_t InstanceSize() { |
| 2629 ASSERT(sizeof(RawContextScope) == OFFSET_OF(RawContextScope, data_)); | 2672 ASSERT(sizeof(RawContextScope) == OFFSET_OF(RawContextScope, data_)); |
| 2630 return 0; | 2673 return 0; |
| 2631 } | 2674 } |
| 2632 | 2675 |
| 2633 static intptr_t InstanceSize(intptr_t num_variables) { | 2676 static intptr_t InstanceSize(intptr_t len) { |
| 2634 return RoundedAllocationSize(sizeof(RawContextScope) + | 2677 ASSERT(0 <= len && len <= kMaxElements); |
| 2635 (num_variables * sizeof(RawContextScope::VariableDesc))); | 2678 return RoundedAllocationSize( |
| 2679 sizeof(RawContextScope) + (len * kBytesPerElement)); |
| 2636 } | 2680 } |
| 2637 | 2681 |
| 2638 static RawContextScope* New(intptr_t num_variables); | 2682 static RawContextScope* New(intptr_t num_variables); |
| 2639 | 2683 |
| 2640 private: | 2684 private: |
| 2641 void set_num_variables(intptr_t num_variables) const { | 2685 void set_num_variables(intptr_t num_variables) const { |
| 2642 raw_ptr()->num_variables_ = num_variables; | 2686 raw_ptr()->num_variables_ = num_variables; |
| 2643 } | 2687 } |
| 2644 | 2688 |
| 2645 RawContextScope::VariableDesc* VariableDescAddr(intptr_t index) const { | 2689 RawContextScope::VariableDesc* VariableDescAddr(intptr_t index) const { |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2994 // Returns 0, -1 or 1. | 3038 // Returns 0, -1 or 1. |
| 2995 virtual int CompareWith(const Integer& other) const; | 3039 virtual int CompareWith(const Integer& other) const; |
| 2996 | 3040 |
| 2997 OBJECT_IMPLEMENTATION(Integer, Number); | 3041 OBJECT_IMPLEMENTATION(Integer, Number); |
| 2998 friend class Class; | 3042 friend class Class; |
| 2999 }; | 3043 }; |
| 3000 | 3044 |
| 3001 | 3045 |
| 3002 class Smi : public Integer { | 3046 class Smi : public Integer { |
| 3003 public: | 3047 public: |
| 3004 // Smi value range is from -(2^N) to (2^N)-1. | 3048 static const intptr_t kBits = kSmiBits; |
| 3005 // N=30 (32-bit build) or N=62 (64-bit build). | 3049 static const intptr_t kMaxValue = kSmiMax; |
| 3006 static const intptr_t kBits = kBitsPerWord - 2; | 3050 static const intptr_t kMinValue = kSmiMin; |
| 3007 static const intptr_t kMaxValue = (static_cast<intptr_t>(1) << kBits) - 1; | |
| 3008 static const intptr_t kMinValue = -(static_cast<intptr_t>(1) << kBits); | |
| 3009 | 3051 |
| 3010 intptr_t Value() const { | 3052 intptr_t Value() const { |
| 3011 return ValueFromRaw(raw_value()); | 3053 return ValueFromRaw(raw_value()); |
| 3012 } | 3054 } |
| 3013 | 3055 |
| 3014 virtual bool Equals(const Instance& other) const; | 3056 virtual bool Equals(const Instance& other) const; |
| 3015 virtual bool IsZero() const { return Value() == 0; } | 3057 virtual bool IsZero() const { return Value() == 0; } |
| 3016 virtual bool IsNegative() const { return Value() < 0; } | 3058 virtual bool IsNegative() const { return Value() < 0; } |
| 3017 // Smi values are implicitly canonicalized. | 3059 // Smi values are implicitly canonicalized. |
| 3018 virtual RawInstance* Canonicalize() const { | 3060 virtual RawInstance* Canonicalize() const { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3101 | 3143 |
| 3102 private: | 3144 private: |
| 3103 void set_value(int64_t value) const; | 3145 void set_value(int64_t value) const; |
| 3104 | 3146 |
| 3105 HEAP_OBJECT_IMPLEMENTATION(Mint, Integer); | 3147 HEAP_OBJECT_IMPLEMENTATION(Mint, Integer); |
| 3106 friend class Class; | 3148 friend class Class; |
| 3107 }; | 3149 }; |
| 3108 | 3150 |
| 3109 | 3151 |
| 3110 class Bigint : public Integer { | 3152 class Bigint : public Integer { |
| 3153 private: |
| 3154 typedef uint32_t Chunk; |
| 3155 typedef uint64_t DoubleChunk; |
| 3156 static const int kChunkSize = sizeof(Chunk); |
| 3157 |
| 3111 public: | 3158 public: |
| 3112 virtual bool IsZero() const { return raw_ptr()->signed_length_ == 0; } | 3159 virtual bool IsZero() const { return raw_ptr()->signed_length_ == 0; } |
| 3113 virtual bool IsNegative() const { return raw_ptr()->signed_length_ < 0; } | 3160 virtual bool IsNegative() const { return raw_ptr()->signed_length_ < 0; } |
| 3114 | 3161 |
| 3115 virtual bool Equals(const Instance& other) const; | 3162 virtual bool Equals(const Instance& other) const; |
| 3116 | 3163 |
| 3117 virtual double AsDoubleValue() const; | 3164 virtual double AsDoubleValue() const; |
| 3118 virtual int64_t AsInt64Value() const; | 3165 virtual int64_t AsInt64Value() const; |
| 3119 | 3166 |
| 3120 virtual int CompareWith(const Integer& other) const; | 3167 virtual int CompareWith(const Integer& other) const; |
| 3121 | 3168 |
| 3122 static intptr_t InstanceSize(intptr_t length) { | 3169 static const intptr_t kBytesPerElement = kChunkSize; |
| 3123 ASSERT(length >= 0); | 3170 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 3124 return RoundedAllocationSize(sizeof(RawBigint) + (length * sizeof(Chunk))); | 3171 |
| 3172 static intptr_t InstanceSize() { return 0; } |
| 3173 |
| 3174 static intptr_t InstanceSize(intptr_t len) { |
| 3175 ASSERT(0 <= len && len <= kMaxElements); |
| 3176 return RoundedAllocationSize(sizeof(RawBigint) + (len * kBytesPerElement)); |
| 3125 } | 3177 } |
| 3126 static intptr_t InstanceSize() { return 0; } | |
| 3127 | 3178 |
| 3128 static RawBigint* New(const String& str, Heap::Space space = Heap::kNew); | 3179 static RawBigint* New(const String& str, Heap::Space space = Heap::kNew); |
| 3129 static RawBigint* New(int64_t value, Heap::Space space = Heap::kNew); | 3180 static RawBigint* New(int64_t value, Heap::Space space = Heap::kNew); |
| 3130 | 3181 |
| 3131 private: | 3182 private: |
| 3132 typedef uint32_t Chunk; | |
| 3133 typedef uint64_t DoubleChunk; | |
| 3134 static const int kChunkSize = sizeof(Chunk); | |
| 3135 | |
| 3136 Chunk GetChunkAt(intptr_t i) const { | 3183 Chunk GetChunkAt(intptr_t i) const { |
| 3137 return *ChunkAddr(i); | 3184 return *ChunkAddr(i); |
| 3138 } | 3185 } |
| 3139 | 3186 |
| 3140 void SetChunkAt(intptr_t i, Chunk newValue) const { | 3187 void SetChunkAt(intptr_t i, Chunk newValue) const { |
| 3141 *ChunkAddr(i) = newValue; | 3188 *ChunkAddr(i) = newValue; |
| 3142 } | 3189 } |
| 3143 | 3190 |
| 3144 // Returns the number of chunks in use. | 3191 // Returns the number of chunks in use. |
| 3145 intptr_t Length() const { | 3192 intptr_t Length() const { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3219 class String : public Instance { | 3266 class String : public Instance { |
| 3220 public: | 3267 public: |
| 3221 // We use 30 bits for the hash code so that we consistently use a | 3268 // We use 30 bits for the hash code so that we consistently use a |
| 3222 // 32bit Smi representation for the hash code on all architectures. | 3269 // 32bit Smi representation for the hash code on all architectures. |
| 3223 static const intptr_t kHashBits = 30; | 3270 static const intptr_t kHashBits = 30; |
| 3224 | 3271 |
| 3225 static const intptr_t kOneByteChar = 1; | 3272 static const intptr_t kOneByteChar = 1; |
| 3226 static const intptr_t kTwoByteChar = 2; | 3273 static const intptr_t kTwoByteChar = 2; |
| 3227 static const intptr_t kFourByteChar = 4; | 3274 static const intptr_t kFourByteChar = 4; |
| 3228 | 3275 |
| 3276 // All strings share the same maximum element count to keep things |
| 3277 // simple. We choose a value that will prevent integer overflow for |
| 3278 // 4 byte strings, since it is the worst case. |
| 3279 static const intptr_t kSizeofRawString = sizeof(RawObject) + (2 * kWordSize); |
| 3280 static const intptr_t kMaxElements = kSmiMax / kFourByteChar; |
| 3281 |
| 3229 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } | 3282 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } |
| 3230 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } | 3283 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } |
| 3231 | 3284 |
| 3232 virtual intptr_t Hash() const; | 3285 virtual intptr_t Hash() const; |
| 3233 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } | 3286 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } |
| 3234 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); | 3287 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); |
| 3235 static intptr_t Hash(const uint8_t* characters, intptr_t len); | 3288 static intptr_t Hash(const uint8_t* characters, intptr_t len); |
| 3236 static intptr_t Hash(const uint16_t* characters, intptr_t len); | 3289 static intptr_t Hash(const uint16_t* characters, intptr_t len); |
| 3237 static intptr_t Hash(const uint32_t* characters, intptr_t len); | 3290 static intptr_t Hash(const uint32_t* characters, intptr_t len); |
| 3238 | 3291 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3375 } | 3428 } |
| 3376 | 3429 |
| 3377 virtual intptr_t CharSize() const { | 3430 virtual intptr_t CharSize() const { |
| 3378 return kOneByteChar; | 3431 return kOneByteChar; |
| 3379 } | 3432 } |
| 3380 | 3433 |
| 3381 RawOneByteString* EscapeDoubleQuotes() const; | 3434 RawOneByteString* EscapeDoubleQuotes() const; |
| 3382 | 3435 |
| 3383 bool EqualsIgnoringPrivateKey(const OneByteString& str) const; | 3436 bool EqualsIgnoringPrivateKey(const OneByteString& str) const; |
| 3384 | 3437 |
| 3438 // We use the same maximum elements for all strings. |
| 3439 static const intptr_t kBytesPerElement = 1; |
| 3440 static const intptr_t kMaxElements = String::kMaxElements; |
| 3441 |
| 3385 static intptr_t data_offset() { return OFFSET_OF(RawOneByteString, data_); } | 3442 static intptr_t data_offset() { return OFFSET_OF(RawOneByteString, data_); } |
| 3386 | 3443 |
| 3387 static intptr_t InstanceSize() { | 3444 static intptr_t InstanceSize() { |
| 3388 ASSERT(sizeof(RawOneByteString) == OFFSET_OF(RawOneByteString, data_)); | 3445 ASSERT(sizeof(RawOneByteString) == OFFSET_OF(RawOneByteString, data_)); |
| 3389 return 0; | 3446 return 0; |
| 3390 } | 3447 } |
| 3391 | 3448 |
| 3392 static intptr_t InstanceSize(intptr_t len) { | 3449 static intptr_t InstanceSize(intptr_t len) { |
| 3393 return RoundedAllocationSize(sizeof(RawOneByteString) + len); | 3450 ASSERT(sizeof(RawOneByteString) == kSizeofRawString); |
| 3451 ASSERT(0 <= len && len <= kMaxElements); |
| 3452 return RoundedAllocationSize( |
| 3453 sizeof(RawOneByteString) + (len * kBytesPerElement)); |
| 3394 } | 3454 } |
| 3395 | 3455 |
| 3396 static RawOneByteString* New(intptr_t len, | 3456 static RawOneByteString* New(intptr_t len, |
| 3397 Heap::Space space); | 3457 Heap::Space space); |
| 3398 static RawOneByteString* New(const char* c_string, | 3458 static RawOneByteString* New(const char* c_string, |
| 3399 Heap::Space space = Heap::kNew) { | 3459 Heap::Space space = Heap::kNew) { |
| 3400 return New(reinterpret_cast<const uint8_t*>(c_string), | 3460 return New(reinterpret_cast<const uint8_t*>(c_string), |
| 3401 strlen(c_string), | 3461 strlen(c_string), |
| 3402 space); | 3462 space); |
| 3403 } | 3463 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3442 virtual int32_t CharAt(intptr_t index) const { | 3502 virtual int32_t CharAt(intptr_t index) const { |
| 3443 return *CharAddr(index); | 3503 return *CharAddr(index); |
| 3444 } | 3504 } |
| 3445 | 3505 |
| 3446 virtual intptr_t CharSize() const { | 3506 virtual intptr_t CharSize() const { |
| 3447 return kTwoByteChar; | 3507 return kTwoByteChar; |
| 3448 } | 3508 } |
| 3449 | 3509 |
| 3450 RawTwoByteString* EscapeDoubleQuotes() const; | 3510 RawTwoByteString* EscapeDoubleQuotes() const; |
| 3451 | 3511 |
| 3512 // We use the same maximum elements for all strings. |
| 3513 static const intptr_t kBytesPerElement = 2; |
| 3514 static const intptr_t kMaxElements = String::kMaxElements; |
| 3515 |
| 3452 static intptr_t InstanceSize() { | 3516 static intptr_t InstanceSize() { |
| 3453 ASSERT(sizeof(RawTwoByteString) == OFFSET_OF(RawTwoByteString, data_)); | 3517 ASSERT(sizeof(RawTwoByteString) == OFFSET_OF(RawTwoByteString, data_)); |
| 3454 return 0; | 3518 return 0; |
| 3455 } | 3519 } |
| 3456 | 3520 |
| 3457 static intptr_t InstanceSize(intptr_t len) { | 3521 static intptr_t InstanceSize(intptr_t len) { |
| 3458 return RoundedAllocationSize(sizeof(RawTwoByteString) + (2 * len)); | 3522 ASSERT(sizeof(RawTwoByteString) == kSizeofRawString); |
| 3523 ASSERT(0 <= len && len <= kMaxElements); |
| 3524 return RoundedAllocationSize( |
| 3525 sizeof(RawTwoByteString) + (len * kBytesPerElement)); |
| 3459 } | 3526 } |
| 3460 | 3527 |
| 3461 static RawTwoByteString* New(intptr_t len, | 3528 static RawTwoByteString* New(intptr_t len, |
| 3462 Heap::Space space); | 3529 Heap::Space space); |
| 3463 static RawTwoByteString* New(const uint16_t* characters, | 3530 static RawTwoByteString* New(const uint16_t* characters, |
| 3464 intptr_t len, | 3531 intptr_t len, |
| 3465 Heap::Space space); | 3532 Heap::Space space); |
| 3466 static RawTwoByteString* New(const uint32_t* characters, | 3533 static RawTwoByteString* New(const uint32_t* characters, |
| 3467 intptr_t len, | 3534 intptr_t len, |
| 3468 Heap::Space space); | 3535 Heap::Space space); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3497 virtual int32_t CharAt(intptr_t index) const { | 3564 virtual int32_t CharAt(intptr_t index) const { |
| 3498 return *CharAddr(index); | 3565 return *CharAddr(index); |
| 3499 } | 3566 } |
| 3500 | 3567 |
| 3501 virtual intptr_t CharSize() const { | 3568 virtual intptr_t CharSize() const { |
| 3502 return kFourByteChar; | 3569 return kFourByteChar; |
| 3503 } | 3570 } |
| 3504 | 3571 |
| 3505 RawFourByteString* EscapeDoubleQuotes() const; | 3572 RawFourByteString* EscapeDoubleQuotes() const; |
| 3506 | 3573 |
| 3574 static const intptr_t kBytesPerElement = 4; |
| 3575 static const intptr_t kMaxElements = String::kMaxElements; |
| 3576 |
| 3507 static intptr_t InstanceSize() { | 3577 static intptr_t InstanceSize() { |
| 3508 ASSERT(sizeof(RawFourByteString) == OFFSET_OF(RawFourByteString, data_)); | 3578 ASSERT(sizeof(RawFourByteString) == OFFSET_OF(RawFourByteString, data_)); |
| 3509 return 0; | 3579 return 0; |
| 3510 } | 3580 } |
| 3511 | 3581 |
| 3512 static intptr_t InstanceSize(intptr_t len) { | 3582 static intptr_t InstanceSize(intptr_t len) { |
| 3513 return RoundedAllocationSize(sizeof(RawFourByteString) + (4 * len)); | 3583 ASSERT(sizeof(RawTwoByteString) == kSizeofRawString); |
| 3584 ASSERT(0 <= len && len <= kMaxElements); |
| 3585 return RoundedAllocationSize( |
| 3586 sizeof(RawFourByteString) + (len * kBytesPerElement)); |
| 3514 } | 3587 } |
| 3515 | 3588 |
| 3516 static RawFourByteString* New(intptr_t len, | 3589 static RawFourByteString* New(intptr_t len, |
| 3517 Heap::Space space); | 3590 Heap::Space space); |
| 3518 static RawFourByteString* New(const uint32_t* characters, | 3591 static RawFourByteString* New(const uint32_t* characters, |
| 3519 intptr_t len, | 3592 intptr_t len, |
| 3520 Heap::Space space); | 3593 Heap::Space space); |
| 3521 static RawFourByteString* New(const FourByteString& str, | 3594 static RawFourByteString* New(const FourByteString& str, |
| 3522 Heap::Space space); | 3595 Heap::Space space); |
| 3523 | 3596 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3552 | 3625 |
| 3553 virtual intptr_t CharSize() const { | 3626 virtual intptr_t CharSize() const { |
| 3554 return kOneByteChar; | 3627 return kOneByteChar; |
| 3555 } | 3628 } |
| 3556 | 3629 |
| 3557 virtual bool IsExternal() const { return true; } | 3630 virtual bool IsExternal() const { return true; } |
| 3558 virtual void* GetPeer() const { | 3631 virtual void* GetPeer() const { |
| 3559 return raw_ptr()->external_data_->peer(); | 3632 return raw_ptr()->external_data_->peer(); |
| 3560 } | 3633 } |
| 3561 | 3634 |
| 3635 // We use the same maximum elements for all strings. |
| 3636 static const intptr_t kBytesPerElement = 1; |
| 3637 static const intptr_t kMaxElements = String::kMaxElements; |
| 3638 |
| 3562 static intptr_t InstanceSize() { | 3639 static intptr_t InstanceSize() { |
| 3563 return RoundedAllocationSize(sizeof(RawExternalOneByteString)); | 3640 return RoundedAllocationSize(sizeof(RawExternalOneByteString)); |
| 3564 } | 3641 } |
| 3565 | 3642 |
| 3566 static RawExternalOneByteString* New(const uint8_t* characters, | 3643 static RawExternalOneByteString* New(const uint8_t* characters, |
| 3567 intptr_t len, | 3644 intptr_t len, |
| 3568 void* peer, | 3645 void* peer, |
| 3569 Dart_PeerFinalizer callback, | 3646 Dart_PeerFinalizer callback, |
| 3570 Heap::Space space); | 3647 Heap::Space space); |
| 3571 | 3648 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3596 | 3673 |
| 3597 virtual intptr_t CharSize() const { | 3674 virtual intptr_t CharSize() const { |
| 3598 return kTwoByteChar; | 3675 return kTwoByteChar; |
| 3599 } | 3676 } |
| 3600 | 3677 |
| 3601 virtual bool IsExternal() const { return true; } | 3678 virtual bool IsExternal() const { return true; } |
| 3602 virtual void* GetPeer() const { | 3679 virtual void* GetPeer() const { |
| 3603 return raw_ptr()->external_data_->peer(); | 3680 return raw_ptr()->external_data_->peer(); |
| 3604 } | 3681 } |
| 3605 | 3682 |
| 3683 // We use the same maximum elements for all strings. |
| 3684 static const intptr_t kBytesPerElement = 2; |
| 3685 static const intptr_t kMaxElements = String::kMaxElements; |
| 3686 |
| 3606 static intptr_t InstanceSize() { | 3687 static intptr_t InstanceSize() { |
| 3607 return RoundedAllocationSize(sizeof(RawExternalTwoByteString)); | 3688 return RoundedAllocationSize(sizeof(RawExternalTwoByteString)); |
| 3608 } | 3689 } |
| 3609 | 3690 |
| 3610 static RawExternalTwoByteString* New(const uint16_t* characters, | 3691 static RawExternalTwoByteString* New(const uint16_t* characters, |
| 3611 intptr_t len, | 3692 intptr_t len, |
| 3612 void* peer, | 3693 void* peer, |
| 3613 Dart_PeerFinalizer callback, | 3694 Dart_PeerFinalizer callback, |
| 3614 Heap::Space space = Heap::kNew); | 3695 Heap::Space space = Heap::kNew); |
| 3615 | 3696 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3640 | 3721 |
| 3641 virtual intptr_t CharSize() const { | 3722 virtual intptr_t CharSize() const { |
| 3642 return kFourByteChar; | 3723 return kFourByteChar; |
| 3643 } | 3724 } |
| 3644 | 3725 |
| 3645 virtual bool IsExternal() const { return true; } | 3726 virtual bool IsExternal() const { return true; } |
| 3646 virtual void* GetPeer() const { | 3727 virtual void* GetPeer() const { |
| 3647 return raw_ptr()->external_data_->peer(); | 3728 return raw_ptr()->external_data_->peer(); |
| 3648 } | 3729 } |
| 3649 | 3730 |
| 3731 // We use the same maximum elements for all strings. |
| 3732 static const intptr_t kBytesPerElement = 4; |
| 3733 static const intptr_t kMaxElements = String::kMaxElements; |
| 3734 |
| 3650 static intptr_t InstanceSize() { | 3735 static intptr_t InstanceSize() { |
| 3651 return RoundedAllocationSize(sizeof(RawExternalFourByteString)); | 3736 return RoundedAllocationSize(sizeof(RawExternalFourByteString)); |
| 3652 } | 3737 } |
| 3653 | 3738 |
| 3654 static RawExternalFourByteString* New(const uint32_t* characters, | 3739 static RawExternalFourByteString* New(const uint32_t* characters, |
| 3655 intptr_t len, | 3740 intptr_t len, |
| 3656 void* peer, | 3741 void* peer, |
| 3657 Dart_PeerFinalizer callback, | 3742 Dart_PeerFinalizer callback, |
| 3658 Heap::Space space = Heap::kNew); | 3743 Heap::Space space = Heap::kNew); |
| 3659 | 3744 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3724 | 3809 |
| 3725 virtual RawAbstractTypeArguments* GetTypeArguments() const { | 3810 virtual RawAbstractTypeArguments* GetTypeArguments() const { |
| 3726 return raw_ptr()->type_arguments_; | 3811 return raw_ptr()->type_arguments_; |
| 3727 } | 3812 } |
| 3728 virtual void SetTypeArguments(const AbstractTypeArguments& value) const { | 3813 virtual void SetTypeArguments(const AbstractTypeArguments& value) const { |
| 3729 StorePointer(&raw_ptr()->type_arguments_, value.raw()); | 3814 StorePointer(&raw_ptr()->type_arguments_, value.raw()); |
| 3730 } | 3815 } |
| 3731 | 3816 |
| 3732 virtual bool Equals(const Instance& other) const; | 3817 virtual bool Equals(const Instance& other) const; |
| 3733 | 3818 |
| 3819 static const intptr_t kBytesPerElement = kWordSize; |
| 3820 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 3821 |
| 3734 static intptr_t type_arguments_offset() { | 3822 static intptr_t type_arguments_offset() { |
| 3735 return OFFSET_OF(RawArray, type_arguments_); | 3823 return OFFSET_OF(RawArray, type_arguments_); |
| 3736 } | 3824 } |
| 3737 | 3825 |
| 3738 static intptr_t InstanceSize() { | 3826 static intptr_t InstanceSize() { |
| 3739 ASSERT(sizeof(RawArray) == OFFSET_OF_RETURNED_VALUE(RawArray, data)); | 3827 ASSERT(sizeof(RawArray) == OFFSET_OF_RETURNED_VALUE(RawArray, data)); |
| 3740 return 0; | 3828 return 0; |
| 3741 } | 3829 } |
| 3742 | 3830 |
| 3743 static intptr_t InstanceSize(intptr_t len) { | 3831 static intptr_t InstanceSize(intptr_t len) { |
| 3744 // Ensure that variable length data is not adding to the object length. | 3832 // Ensure that variable length data is not adding to the object length. |
| 3745 ASSERT(sizeof(RawArray) == (sizeof(RawObject) + (2 * kWordSize))); | 3833 ASSERT(sizeof(RawArray) == (sizeof(RawObject) + (2 * kWordSize))); |
| 3746 return RoundedAllocationSize(sizeof(RawArray) + (len * kWordSize)); | 3834 ASSERT(0 <= len && len <= kMaxElements); |
| 3835 return RoundedAllocationSize(sizeof(RawArray) + (len * kBytesPerElement)); |
| 3747 } | 3836 } |
| 3748 | 3837 |
| 3749 // Make the array immutable to Dart code by switching the class pointer | 3838 // Make the array immutable to Dart code by switching the class pointer |
| 3750 // to ImmutableArray. | 3839 // to ImmutableArray. |
| 3751 void MakeImmutable() const; | 3840 void MakeImmutable() const; |
| 3752 | 3841 |
| 3753 static RawArray* New(intptr_t len, Heap::Space space = Heap::kNew); | 3842 static RawArray* New(intptr_t len, Heap::Space space = Heap::kNew); |
| 3754 | 3843 |
| 3755 // Creates and returns a new array with 'new_length'. Copies all elements from | 3844 // Creates and returns a new array with 'new_length'. Copies all elements from |
| 3756 // 'source' to the new array. 'new_length' must be greater than or equal to | 3845 // 'source' to the new array. 'new_length' must be greater than or equal to |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3771 // collection. The backing array of the original Growable Object Array is | 3860 // collection. The backing array of the original Growable Object Array is |
| 3772 // set to an empty array. | 3861 // set to an empty array. |
| 3773 static RawArray* MakeArray(const GrowableObjectArray& growable_array); | 3862 static RawArray* MakeArray(const GrowableObjectArray& growable_array); |
| 3774 | 3863 |
| 3775 protected: | 3864 protected: |
| 3776 static RawArray* New(const Class& cls, | 3865 static RawArray* New(const Class& cls, |
| 3777 intptr_t len, | 3866 intptr_t len, |
| 3778 Heap::Space space = Heap::kNew); | 3867 Heap::Space space = Heap::kNew); |
| 3779 | 3868 |
| 3780 private: | 3869 private: |
| 3781 // Make sure that the array size cannot wrap around. | |
| 3782 static const intptr_t kMaxArrayElements = 512 * 1024 * 1024; | |
| 3783 | |
| 3784 RawObject** ObjectAddr(intptr_t index) const { | 3870 RawObject** ObjectAddr(intptr_t index) const { |
| 3785 // TODO(iposva): Determine if we should throw an exception here. | 3871 // TODO(iposva): Determine if we should throw an exception here. |
| 3786 ASSERT((index >= 0) && (index < Length())); | 3872 ASSERT((index >= 0) && (index < Length())); |
| 3787 return &raw_ptr()->data()[index]; | 3873 return &raw_ptr()->data()[index]; |
| 3788 } | 3874 } |
| 3789 | 3875 |
| 3790 void SetLength(intptr_t value) const { | 3876 void SetLength(intptr_t value) const { |
| 3791 // This is only safe because we create a new Smi, which does not cause | 3877 // This is only safe because we create a new Smi, which does not cause |
| 3792 // heap allocation. | 3878 // heap allocation. |
| 3793 raw_ptr()->length_ = Smi::New(value); | 3879 raw_ptr()->length_ = Smi::New(value); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3975 int8_t At(intptr_t index) const { | 4061 int8_t At(intptr_t index) const { |
| 3976 ASSERT((index >= 0) && (index < Length())); | 4062 ASSERT((index >= 0) && (index < Length())); |
| 3977 return raw_ptr()->data_[index]; | 4063 return raw_ptr()->data_[index]; |
| 3978 } | 4064 } |
| 3979 | 4065 |
| 3980 void SetAt(intptr_t index, int8_t value) const { | 4066 void SetAt(intptr_t index, int8_t value) const { |
| 3981 ASSERT((index >= 0) && (index < Length())); | 4067 ASSERT((index >= 0) && (index < Length())); |
| 3982 raw_ptr()->data_[index] = value; | 4068 raw_ptr()->data_[index] = value; |
| 3983 } | 4069 } |
| 3984 | 4070 |
| 4071 static const intptr_t kBytesPerElement = 1; |
| 4072 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 4073 |
| 3985 static intptr_t data_offset() { | 4074 static intptr_t data_offset() { |
| 3986 return length_offset() + kWordSize; | 4075 return length_offset() + kWordSize; |
| 3987 } | 4076 } |
| 3988 | 4077 |
| 3989 static intptr_t InstanceSize() { | 4078 static intptr_t InstanceSize() { |
| 3990 ASSERT(sizeof(RawInt8Array) == OFFSET_OF(RawInt8Array, data_)); | 4079 ASSERT(sizeof(RawInt8Array) == OFFSET_OF(RawInt8Array, data_)); |
| 3991 return 0; | 4080 return 0; |
| 3992 } | 4081 } |
| 3993 | 4082 |
| 3994 static intptr_t InstanceSize(intptr_t len) { | 4083 static intptr_t InstanceSize(intptr_t len) { |
| 3995 return RoundedAllocationSize(sizeof(RawInt8Array) + len); | 4084 ASSERT(0 <= len && len <= kMaxElements); |
| 4085 return RoundedAllocationSize( |
| 4086 sizeof(RawInt8Array) + (len * kBytesPerElement)); |
| 3996 } | 4087 } |
| 3997 | 4088 |
| 3998 static RawInt8Array* New(intptr_t len, | 4089 static RawInt8Array* New(intptr_t len, |
| 3999 Heap::Space space = Heap::kNew); | 4090 Heap::Space space = Heap::kNew); |
| 4000 static RawInt8Array* New(const int8_t* data, | 4091 static RawInt8Array* New(const int8_t* data, |
| 4001 intptr_t len, | 4092 intptr_t len, |
| 4002 Heap::Space space = Heap::kNew); | 4093 Heap::Space space = Heap::kNew); |
| 4003 | 4094 |
| 4004 private: | 4095 private: |
| 4005 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4096 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4022 uint8_t At(intptr_t index) const { | 4113 uint8_t At(intptr_t index) const { |
| 4023 ASSERT((index >= 0) && (index < Length())); | 4114 ASSERT((index >= 0) && (index < Length())); |
| 4024 return raw_ptr()->data_[index]; | 4115 return raw_ptr()->data_[index]; |
| 4025 } | 4116 } |
| 4026 | 4117 |
| 4027 void SetAt(intptr_t index, uint8_t value) const { | 4118 void SetAt(intptr_t index, uint8_t value) const { |
| 4028 ASSERT((index >= 0) && (index < Length())); | 4119 ASSERT((index >= 0) && (index < Length())); |
| 4029 raw_ptr()->data_[index] = value; | 4120 raw_ptr()->data_[index] = value; |
| 4030 } | 4121 } |
| 4031 | 4122 |
| 4123 static const intptr_t kBytesPerElement = 1; |
| 4124 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 4125 |
| 4032 static intptr_t data_offset() { | 4126 static intptr_t data_offset() { |
| 4033 return length_offset() + kWordSize; | 4127 return length_offset() + kWordSize; |
| 4034 } | 4128 } |
| 4035 | 4129 |
| 4036 static intptr_t InstanceSize() { | 4130 static intptr_t InstanceSize() { |
| 4037 ASSERT(sizeof(RawUint8Array) == OFFSET_OF(RawUint8Array, data_)); | 4131 ASSERT(sizeof(RawUint8Array) == OFFSET_OF(RawUint8Array, data_)); |
| 4038 return 0; | 4132 return 0; |
| 4039 } | 4133 } |
| 4040 | 4134 |
| 4041 static intptr_t InstanceSize(intptr_t len) { | 4135 static intptr_t InstanceSize(intptr_t len) { |
| 4042 return RoundedAllocationSize(sizeof(RawUint8Array) + len); | 4136 ASSERT(0 <= len && len <= kMaxElements); |
| 4137 return RoundedAllocationSize( |
| 4138 sizeof(RawUint8Array) + (len * kBytesPerElement)); |
| 4043 } | 4139 } |
| 4044 | 4140 |
| 4045 static RawUint8Array* New(intptr_t len, | 4141 static RawUint8Array* New(intptr_t len, |
| 4046 Heap::Space space = Heap::kNew); | 4142 Heap::Space space = Heap::kNew); |
| 4047 static RawUint8Array* New(const uint8_t* data, | 4143 static RawUint8Array* New(const uint8_t* data, |
| 4048 intptr_t len, | 4144 intptr_t len, |
| 4049 Heap::Space space = Heap::kNew); | 4145 Heap::Space space = Heap::kNew); |
| 4050 | 4146 |
| 4051 private: | 4147 private: |
| 4052 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4148 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4069 int16_t At(intptr_t index) const { | 4165 int16_t At(intptr_t index) const { |
| 4070 ASSERT((index >= 0) && (index < Length())); | 4166 ASSERT((index >= 0) && (index < Length())); |
| 4071 return raw_ptr()->data_[index]; | 4167 return raw_ptr()->data_[index]; |
| 4072 } | 4168 } |
| 4073 | 4169 |
| 4074 void SetAt(intptr_t index, int16_t value) const { | 4170 void SetAt(intptr_t index, int16_t value) const { |
| 4075 ASSERT((index >= 0) && (index < Length())); | 4171 ASSERT((index >= 0) && (index < Length())); |
| 4076 raw_ptr()->data_[index] = value; | 4172 raw_ptr()->data_[index] = value; |
| 4077 } | 4173 } |
| 4078 | 4174 |
| 4175 static const intptr_t kBytesPerElement = 2; |
| 4176 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 4177 |
| 4079 static intptr_t data_offset() { | 4178 static intptr_t data_offset() { |
| 4080 return length_offset() + kWordSize; | 4179 return length_offset() + kWordSize; |
| 4081 } | 4180 } |
| 4082 | 4181 |
| 4083 static intptr_t InstanceSize() { | 4182 static intptr_t InstanceSize() { |
| 4084 ASSERT(sizeof(RawInt16Array) == OFFSET_OF(RawInt16Array, data_)); | 4183 ASSERT(sizeof(RawInt16Array) == OFFSET_OF(RawInt16Array, data_)); |
| 4085 return 0; | 4184 return 0; |
| 4086 } | 4185 } |
| 4087 | 4186 |
| 4088 static intptr_t InstanceSize(intptr_t len) { | 4187 static intptr_t InstanceSize(intptr_t len) { |
| 4089 intptr_t data_size = len * kBytesPerElement; | 4188 ASSERT(0 <= len && len <= kMaxElements); |
| 4090 return RoundedAllocationSize(sizeof(RawInt16Array) + data_size); | 4189 return RoundedAllocationSize( |
| 4190 sizeof(RawInt16Array) + (len * kBytesPerElement)); |
| 4091 } | 4191 } |
| 4092 | 4192 |
| 4093 static RawInt16Array* New(intptr_t len, | 4193 static RawInt16Array* New(intptr_t len, |
| 4094 Heap::Space space = Heap::kNew); | 4194 Heap::Space space = Heap::kNew); |
| 4095 static RawInt16Array* New(const int16_t* data, | 4195 static RawInt16Array* New(const int16_t* data, |
| 4096 intptr_t len, | 4196 intptr_t len, |
| 4097 Heap::Space space = Heap::kNew); | 4197 Heap::Space space = Heap::kNew); |
| 4098 | 4198 |
| 4099 private: | 4199 private: |
| 4100 static const intptr_t kBytesPerElement = 2; | |
| 4101 | |
| 4102 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4200 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4103 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4201 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4104 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | 4202 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; |
| 4105 } | 4203 } |
| 4106 | 4204 |
| 4107 HEAP_OBJECT_IMPLEMENTATION(Int16Array, ByteArray); | 4205 HEAP_OBJECT_IMPLEMENTATION(Int16Array, ByteArray); |
| 4108 friend class ByteArray; | 4206 friend class ByteArray; |
| 4109 friend class Class; | 4207 friend class Class; |
| 4110 }; | 4208 }; |
| 4111 | 4209 |
| 4112 | 4210 |
| 4113 class Uint16Array : public ByteArray { | 4211 class Uint16Array : public ByteArray { |
| 4114 public: | 4212 public: |
| 4115 intptr_t ByteLength() const { | 4213 intptr_t ByteLength() const { |
| 4116 return Length() * kBytesPerElement; | 4214 return Length() * kBytesPerElement; |
| 4117 } | 4215 } |
| 4118 | 4216 |
| 4119 uint16_t At(intptr_t index) const { | 4217 uint16_t At(intptr_t index) const { |
| 4120 ASSERT((index >= 0) && (index < Length())); | 4218 ASSERT((index >= 0) && (index < Length())); |
| 4121 return raw_ptr()->data_[index]; | 4219 return raw_ptr()->data_[index]; |
| 4122 } | 4220 } |
| 4123 | 4221 |
| 4124 void SetAt(intptr_t index, uint16_t value) const { | 4222 void SetAt(intptr_t index, uint16_t value) const { |
| 4125 ASSERT((index >= 0) && (index < Length())); | 4223 ASSERT((index >= 0) && (index < Length())); |
| 4126 raw_ptr()->data_[index] = value; | 4224 raw_ptr()->data_[index] = value; |
| 4127 } | 4225 } |
| 4128 | 4226 |
| 4227 static const intptr_t kBytesPerElement = 2; |
| 4228 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 4229 |
| 4129 static intptr_t data_offset() { | 4230 static intptr_t data_offset() { |
| 4130 return length_offset() + kWordSize; | 4231 return length_offset() + kWordSize; |
| 4131 } | 4232 } |
| 4132 | 4233 |
| 4133 static intptr_t InstanceSize() { | 4234 static intptr_t InstanceSize() { |
| 4134 ASSERT(sizeof(RawUint16Array) == OFFSET_OF(RawUint16Array, data_)); | 4235 ASSERT(sizeof(RawUint16Array) == OFFSET_OF(RawUint16Array, data_)); |
| 4135 return 0; | 4236 return 0; |
| 4136 } | 4237 } |
| 4137 | 4238 |
| 4138 static intptr_t InstanceSize(intptr_t len) { | 4239 static intptr_t InstanceSize(intptr_t len) { |
| 4139 intptr_t data_size = len * kBytesPerElement; | 4240 ASSERT(0 <= len && len <= kMaxElements); |
| 4140 return RoundedAllocationSize(sizeof(RawUint16Array) + data_size); | 4241 return RoundedAllocationSize( |
| 4242 sizeof(RawUint16Array) + (len * kBytesPerElement)); |
| 4141 } | 4243 } |
| 4142 | 4244 |
| 4143 static RawUint16Array* New(intptr_t len, | 4245 static RawUint16Array* New(intptr_t len, |
| 4144 Heap::Space space = Heap::kNew); | 4246 Heap::Space space = Heap::kNew); |
| 4145 static RawUint16Array* New(const uint16_t* data, | 4247 static RawUint16Array* New(const uint16_t* data, |
| 4146 intptr_t len, | 4248 intptr_t len, |
| 4147 Heap::Space space = Heap::kNew); | 4249 Heap::Space space = Heap::kNew); |
| 4148 | 4250 |
| 4149 private: | 4251 private: |
| 4150 static const intptr_t kBytesPerElement = 2; | |
| 4151 | |
| 4152 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4252 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4153 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4253 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4154 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | 4254 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; |
| 4155 } | 4255 } |
| 4156 | 4256 |
| 4157 HEAP_OBJECT_IMPLEMENTATION(Uint16Array, ByteArray); | 4257 HEAP_OBJECT_IMPLEMENTATION(Uint16Array, ByteArray); |
| 4158 friend class ByteArray; | 4258 friend class ByteArray; |
| 4159 friend class Class; | 4259 friend class Class; |
| 4160 }; | 4260 }; |
| 4161 | 4261 |
| 4162 | 4262 |
| 4163 class Int32Array : public ByteArray { | 4263 class Int32Array : public ByteArray { |
| 4164 public: | 4264 public: |
| 4165 intptr_t ByteLength() const { | 4265 intptr_t ByteLength() const { |
| 4166 return Length() * kBytesPerElement; | 4266 return Length() * kBytesPerElement; |
| 4167 } | 4267 } |
| 4168 | 4268 |
| 4169 int32_t At(intptr_t index) const { | 4269 int32_t At(intptr_t index) const { |
| 4170 ASSERT((index >= 0) && (index < Length())); | 4270 ASSERT((index >= 0) && (index < Length())); |
| 4171 return raw_ptr()->data_[index]; | 4271 return raw_ptr()->data_[index]; |
| 4172 } | 4272 } |
| 4173 | 4273 |
| 4174 void SetAt(intptr_t index, int32_t value) const { | 4274 void SetAt(intptr_t index, int32_t value) const { |
| 4175 ASSERT((index >= 0) && (index < Length())); | 4275 ASSERT((index >= 0) && (index < Length())); |
| 4176 raw_ptr()->data_[index] = value; | 4276 raw_ptr()->data_[index] = value; |
| 4177 } | 4277 } |
| 4178 | 4278 |
| 4279 static const intptr_t kBytesPerElement = 4; |
| 4280 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 4281 |
| 4179 static intptr_t data_offset() { | 4282 static intptr_t data_offset() { |
| 4180 return length_offset() + kWordSize; | 4283 return length_offset() + kWordSize; |
| 4181 } | 4284 } |
| 4182 | 4285 |
| 4183 static intptr_t InstanceSize() { | 4286 static intptr_t InstanceSize() { |
| 4184 ASSERT(sizeof(RawInt32Array) == OFFSET_OF(RawInt32Array, data_)); | 4287 ASSERT(sizeof(RawInt32Array) == OFFSET_OF(RawInt32Array, data_)); |
| 4185 return 0; | 4288 return 0; |
| 4186 } | 4289 } |
| 4187 | 4290 |
| 4188 static intptr_t InstanceSize(intptr_t len) { | 4291 static intptr_t InstanceSize(intptr_t len) { |
| 4189 intptr_t data_size = len * kBytesPerElement; | 4292 ASSERT(0 <= len && len <= kMaxElements); |
| 4190 return RoundedAllocationSize(sizeof(RawInt32Array) + data_size); | 4293 return RoundedAllocationSize( |
| 4294 sizeof(RawInt32Array) + (len * kBytesPerElement)); |
| 4191 } | 4295 } |
| 4192 | 4296 |
| 4193 static RawInt32Array* New(intptr_t len, | 4297 static RawInt32Array* New(intptr_t len, |
| 4194 Heap::Space space = Heap::kNew); | 4298 Heap::Space space = Heap::kNew); |
| 4195 static RawInt32Array* New(const int32_t* data, | 4299 static RawInt32Array* New(const int32_t* data, |
| 4196 intptr_t len, | 4300 intptr_t len, |
| 4197 Heap::Space space = Heap::kNew); | 4301 Heap::Space space = Heap::kNew); |
| 4198 | 4302 |
| 4199 private: | 4303 private: |
| 4200 static const intptr_t kBytesPerElement = 4; | |
| 4201 | |
| 4202 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4304 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4203 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4305 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4204 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | 4306 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; |
| 4205 } | 4307 } |
| 4206 | 4308 |
| 4207 HEAP_OBJECT_IMPLEMENTATION(Int32Array, ByteArray); | 4309 HEAP_OBJECT_IMPLEMENTATION(Int32Array, ByteArray); |
| 4208 friend class ByteArray; | 4310 friend class ByteArray; |
| 4209 friend class Class; | 4311 friend class Class; |
| 4210 }; | 4312 }; |
| 4211 | 4313 |
| 4212 | 4314 |
| 4213 class Uint32Array : public ByteArray { | 4315 class Uint32Array : public ByteArray { |
| 4214 public: | 4316 public: |
| 4215 intptr_t ByteLength() const { | 4317 intptr_t ByteLength() const { |
| 4216 return Length() * kBytesPerElement; | 4318 return Length() * kBytesPerElement; |
| 4217 } | 4319 } |
| 4218 | 4320 |
| 4219 uint32_t At(intptr_t index) const { | 4321 uint32_t At(intptr_t index) const { |
| 4220 ASSERT((index >= 0) && (index < Length())); | 4322 ASSERT((index >= 0) && (index < Length())); |
| 4221 return raw_ptr()->data_[index]; | 4323 return raw_ptr()->data_[index]; |
| 4222 } | 4324 } |
| 4223 | 4325 |
| 4224 void SetAt(intptr_t index, uint32_t value) const { | 4326 void SetAt(intptr_t index, uint32_t value) const { |
| 4225 ASSERT((index >= 0) && (index < Length())); | 4327 ASSERT((index >= 0) && (index < Length())); |
| 4226 raw_ptr()->data_[index] = value; | 4328 raw_ptr()->data_[index] = value; |
| 4227 } | 4329 } |
| 4228 | 4330 |
| 4331 static const intptr_t kBytesPerElement = 4; |
| 4332 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 4333 |
| 4229 static intptr_t data_offset() { | 4334 static intptr_t data_offset() { |
| 4230 return length_offset() + kWordSize; | 4335 return length_offset() + kWordSize; |
| 4231 } | 4336 } |
| 4232 | 4337 |
| 4233 static intptr_t InstanceSize() { | 4338 static intptr_t InstanceSize() { |
| 4234 ASSERT(sizeof(RawUint32Array) == OFFSET_OF(RawUint32Array, data_)); | 4339 ASSERT(sizeof(RawUint32Array) == OFFSET_OF(RawUint32Array, data_)); |
| 4235 return 0; | 4340 return 0; |
| 4236 } | 4341 } |
| 4237 | 4342 |
| 4238 static intptr_t InstanceSize(intptr_t len) { | 4343 static intptr_t InstanceSize(intptr_t len) { |
| 4239 intptr_t data_size = len * kBytesPerElement; | 4344 ASSERT(0 <= len && len <= kMaxElements); |
| 4240 return RoundedAllocationSize(sizeof(RawUint32Array) + data_size); | 4345 return RoundedAllocationSize( |
| 4346 sizeof(RawUint32Array) + (len * kBytesPerElement)); |
| 4241 } | 4347 } |
| 4242 | 4348 |
| 4243 static RawUint32Array* New(intptr_t len, | 4349 static RawUint32Array* New(intptr_t len, |
| 4244 Heap::Space space = Heap::kNew); | 4350 Heap::Space space = Heap::kNew); |
| 4245 static RawUint32Array* New(const uint32_t* data, | 4351 static RawUint32Array* New(const uint32_t* data, |
| 4246 intptr_t len, | 4352 intptr_t len, |
| 4247 Heap::Space space = Heap::kNew); | 4353 Heap::Space space = Heap::kNew); |
| 4248 | 4354 |
| 4249 private: | 4355 private: |
| 4250 static const intptr_t kBytesPerElement = 4; | |
| 4251 | |
| 4252 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4356 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4253 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4357 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4254 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | 4358 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; |
| 4255 } | 4359 } |
| 4256 | 4360 |
| 4257 HEAP_OBJECT_IMPLEMENTATION(Uint32Array, ByteArray); | 4361 HEAP_OBJECT_IMPLEMENTATION(Uint32Array, ByteArray); |
| 4258 friend class ByteArray; | 4362 friend class ByteArray; |
| 4259 friend class Class; | 4363 friend class Class; |
| 4260 }; | 4364 }; |
| 4261 | 4365 |
| 4262 | 4366 |
| 4263 class Int64Array : public ByteArray { | 4367 class Int64Array : public ByteArray { |
| 4264 public: | 4368 public: |
| 4265 intptr_t ByteLength() const { | 4369 intptr_t ByteLength() const { |
| 4266 return Length() * kBytesPerElement; | 4370 return Length() * kBytesPerElement; |
| 4267 } | 4371 } |
| 4268 | 4372 |
| 4269 int64_t At(intptr_t index) const { | 4373 int64_t At(intptr_t index) const { |
| 4270 ASSERT((index >= 0) && (index < Length())); | 4374 ASSERT((index >= 0) && (index < Length())); |
| 4271 return raw_ptr()->data_[index]; | 4375 return raw_ptr()->data_[index]; |
| 4272 } | 4376 } |
| 4273 | 4377 |
| 4274 void SetAt(intptr_t index, int64_t value) const { | 4378 void SetAt(intptr_t index, int64_t value) const { |
| 4275 ASSERT((index >= 0) && (index < Length())); | 4379 ASSERT((index >= 0) && (index < Length())); |
| 4276 raw_ptr()->data_[index] = value; | 4380 raw_ptr()->data_[index] = value; |
| 4277 } | 4381 } |
| 4278 | 4382 |
| 4383 static const intptr_t kBytesPerElement = 8; |
| 4384 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 4385 |
| 4279 static intptr_t data_offset() { | 4386 static intptr_t data_offset() { |
| 4280 return length_offset() + kWordSize; | 4387 return length_offset() + kWordSize; |
| 4281 } | 4388 } |
| 4282 | 4389 |
| 4283 static intptr_t InstanceSize() { | 4390 static intptr_t InstanceSize() { |
| 4284 ASSERT(sizeof(RawInt64Array) == OFFSET_OF(RawInt64Array, data_)); | 4391 ASSERT(sizeof(RawInt64Array) == OFFSET_OF(RawInt64Array, data_)); |
| 4285 return 0; | 4392 return 0; |
| 4286 } | 4393 } |
| 4287 | 4394 |
| 4288 static intptr_t InstanceSize(intptr_t len) { | 4395 static intptr_t InstanceSize(intptr_t len) { |
| 4289 intptr_t data_size = len * kBytesPerElement; | 4396 ASSERT(0 <= len && len <= kMaxElements); |
| 4290 return RoundedAllocationSize(sizeof(RawInt64Array) + data_size); | 4397 return RoundedAllocationSize( |
| 4398 sizeof(RawInt64Array) + (len * kBytesPerElement)); |
| 4291 } | 4399 } |
| 4292 | 4400 |
| 4293 static RawInt64Array* New(intptr_t len, | 4401 static RawInt64Array* New(intptr_t len, |
| 4294 Heap::Space space = Heap::kNew); | 4402 Heap::Space space = Heap::kNew); |
| 4295 static RawInt64Array* New(const int64_t* data, | 4403 static RawInt64Array* New(const int64_t* data, |
| 4296 intptr_t len, | 4404 intptr_t len, |
| 4297 Heap::Space space = Heap::kNew); | 4405 Heap::Space space = Heap::kNew); |
| 4298 | 4406 |
| 4299 private: | 4407 private: |
| 4300 static const intptr_t kBytesPerElement = 8; | |
| 4301 | |
| 4302 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4408 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4303 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4409 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4304 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | 4410 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; |
| 4305 } | 4411 } |
| 4306 | 4412 |
| 4307 HEAP_OBJECT_IMPLEMENTATION(Int64Array, ByteArray); | 4413 HEAP_OBJECT_IMPLEMENTATION(Int64Array, ByteArray); |
| 4308 friend class ByteArray; | 4414 friend class ByteArray; |
| 4309 friend class Class; | 4415 friend class Class; |
| 4310 }; | 4416 }; |
| 4311 | 4417 |
| 4312 | 4418 |
| 4313 class Uint64Array : public ByteArray { | 4419 class Uint64Array : public ByteArray { |
| 4314 public: | 4420 public: |
| 4315 intptr_t ByteLength() const { | 4421 intptr_t ByteLength() const { |
| 4316 return Length() * sizeof(uint64_t); | 4422 return Length() * sizeof(uint64_t); |
| 4317 } | 4423 } |
| 4318 | 4424 |
| 4319 uint64_t At(intptr_t index) const { | 4425 uint64_t At(intptr_t index) const { |
| 4320 ASSERT((index >= 0) && (index < Length())); | 4426 ASSERT((index >= 0) && (index < Length())); |
| 4321 return raw_ptr()->data_[index]; | 4427 return raw_ptr()->data_[index]; |
| 4322 } | 4428 } |
| 4323 | 4429 |
| 4324 void SetAt(intptr_t index, uint64_t value) const { | 4430 void SetAt(intptr_t index, uint64_t value) const { |
| 4325 ASSERT((index >= 0) && (index < Length())); | 4431 ASSERT((index >= 0) && (index < Length())); |
| 4326 raw_ptr()->data_[index] = value; | 4432 raw_ptr()->data_[index] = value; |
| 4327 } | 4433 } |
| 4328 | 4434 |
| 4435 static const intptr_t kBytesPerElement = 8; |
| 4436 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 4437 |
| 4329 static intptr_t data_offset() { | 4438 static intptr_t data_offset() { |
| 4330 return length_offset() + kWordSize; | 4439 return length_offset() + kWordSize; |
| 4331 } | 4440 } |
| 4332 | 4441 |
| 4333 static intptr_t InstanceSize() { | 4442 static intptr_t InstanceSize() { |
| 4334 ASSERT(sizeof(RawUint64Array) == OFFSET_OF(RawUint64Array, data_)); | 4443 ASSERT(sizeof(RawUint64Array) == OFFSET_OF(RawUint64Array, data_)); |
| 4335 return 0; | 4444 return 0; |
| 4336 } | 4445 } |
| 4337 | 4446 |
| 4338 static intptr_t InstanceSize(intptr_t len) { | 4447 static intptr_t InstanceSize(intptr_t len) { |
| 4339 intptr_t data_size = len * kBytesPerElement; | 4448 ASSERT(0 <= len && len <= kMaxElements); |
| 4340 return RoundedAllocationSize(sizeof(RawUint64Array) + data_size); | 4449 return RoundedAllocationSize( |
| 4450 sizeof(RawUint64Array) + (len * kBytesPerElement)); |
| 4341 } | 4451 } |
| 4342 | 4452 |
| 4343 static RawUint64Array* New(intptr_t len, | 4453 static RawUint64Array* New(intptr_t len, |
| 4344 Heap::Space space = Heap::kNew); | 4454 Heap::Space space = Heap::kNew); |
| 4345 static RawUint64Array* New(const uint64_t* data, | 4455 static RawUint64Array* New(const uint64_t* data, |
| 4346 intptr_t len, | 4456 intptr_t len, |
| 4347 Heap::Space space = Heap::kNew); | 4457 Heap::Space space = Heap::kNew); |
| 4348 | 4458 |
| 4349 private: | 4459 private: |
| 4350 static const intptr_t kBytesPerElement = 8; | |
| 4351 | |
| 4352 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4460 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4353 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4461 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4354 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | 4462 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; |
| 4355 } | 4463 } |
| 4356 | 4464 |
| 4357 HEAP_OBJECT_IMPLEMENTATION(Uint64Array, ByteArray); | 4465 HEAP_OBJECT_IMPLEMENTATION(Uint64Array, ByteArray); |
| 4358 friend class ByteArray; | 4466 friend class ByteArray; |
| 4359 friend class Class; | 4467 friend class Class; |
| 4360 }; | 4468 }; |
| 4361 | 4469 |
| 4362 | 4470 |
| 4363 class Float32Array : public ByteArray { | 4471 class Float32Array : public ByteArray { |
| 4364 public: | 4472 public: |
| 4365 intptr_t ByteLength() const { | 4473 intptr_t ByteLength() const { |
| 4366 return Length() * kBytesPerElement; | 4474 return Length() * kBytesPerElement; |
| 4367 } | 4475 } |
| 4368 | 4476 |
| 4369 float At(intptr_t index) const { | 4477 float At(intptr_t index) const { |
| 4370 ASSERT((index >= 0) && (index < Length())); | 4478 ASSERT((index >= 0) && (index < Length())); |
| 4371 return raw_ptr()->data_[index]; | 4479 return raw_ptr()->data_[index]; |
| 4372 } | 4480 } |
| 4373 | 4481 |
| 4374 void SetAt(intptr_t index, float value) const { | 4482 void SetAt(intptr_t index, float value) const { |
| 4375 ASSERT((index >= 0) && (index < Length())); | 4483 ASSERT((index >= 0) && (index < Length())); |
| 4376 raw_ptr()->data_[index] = value; | 4484 raw_ptr()->data_[index] = value; |
| 4377 } | 4485 } |
| 4378 | 4486 |
| 4487 static const intptr_t kBytesPerElement = 4; |
| 4488 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 4489 |
| 4379 static intptr_t data_offset() { | 4490 static intptr_t data_offset() { |
| 4380 return length_offset() + kWordSize; | 4491 return length_offset() + kWordSize; |
| 4381 } | 4492 } |
| 4382 | 4493 |
| 4383 static intptr_t InstanceSize() { | 4494 static intptr_t InstanceSize() { |
| 4384 ASSERT(sizeof(RawFloat32Array) == OFFSET_OF(RawFloat32Array, data_)); | 4495 ASSERT(sizeof(RawFloat32Array) == OFFSET_OF(RawFloat32Array, data_)); |
| 4385 return 0; | 4496 return 0; |
| 4386 } | 4497 } |
| 4387 | 4498 |
| 4388 static intptr_t InstanceSize(intptr_t len) { | 4499 static intptr_t InstanceSize(intptr_t len) { |
| 4389 intptr_t data_size = len * kBytesPerElement; | 4500 ASSERT(0 <= len && len <= kMaxElements); |
| 4390 return RoundedAllocationSize(sizeof(RawFloat32Array) + data_size); | 4501 return RoundedAllocationSize( |
| 4502 sizeof(RawFloat32Array) + (len * kBytesPerElement)); |
| 4391 } | 4503 } |
| 4392 | 4504 |
| 4393 static RawFloat32Array* New(intptr_t len, | 4505 static RawFloat32Array* New(intptr_t len, |
| 4394 Heap::Space space = Heap::kNew); | 4506 Heap::Space space = Heap::kNew); |
| 4395 static RawFloat32Array* New(const float* data, | 4507 static RawFloat32Array* New(const float* data, |
| 4396 intptr_t len, | 4508 intptr_t len, |
| 4397 Heap::Space space = Heap::kNew); | 4509 Heap::Space space = Heap::kNew); |
| 4398 | 4510 |
| 4399 private: | 4511 private: |
| 4400 static const intptr_t kBytesPerElement = 4; | |
| 4401 | |
| 4402 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4512 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4403 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4513 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4404 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | 4514 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; |
| 4405 } | 4515 } |
| 4406 | 4516 |
| 4407 HEAP_OBJECT_IMPLEMENTATION(Float32Array, ByteArray); | 4517 HEAP_OBJECT_IMPLEMENTATION(Float32Array, ByteArray); |
| 4408 friend class ByteArray; | 4518 friend class ByteArray; |
| 4409 friend class Class; | 4519 friend class Class; |
| 4410 }; | 4520 }; |
| 4411 | 4521 |
| 4412 | 4522 |
| 4413 class Float64Array : public ByteArray { | 4523 class Float64Array : public ByteArray { |
| 4414 public: | 4524 public: |
| 4415 intptr_t ByteLength() const { | 4525 intptr_t ByteLength() const { |
| 4416 return Length() * kBytesPerElement; | 4526 return Length() * kBytesPerElement; |
| 4417 } | 4527 } |
| 4418 | 4528 |
| 4419 double At(intptr_t index) const { | 4529 double At(intptr_t index) const { |
| 4420 ASSERT((index >= 0) && (index < Length())); | 4530 ASSERT((index >= 0) && (index < Length())); |
| 4421 return raw_ptr()->data_[index]; | 4531 return raw_ptr()->data_[index]; |
| 4422 } | 4532 } |
| 4423 | 4533 |
| 4424 void SetAt(intptr_t index, double value) const { | 4534 void SetAt(intptr_t index, double value) const { |
| 4425 ASSERT((index >= 0) && (index < Length())); | 4535 ASSERT((index >= 0) && (index < Length())); |
| 4426 raw_ptr()->data_[index] = value; | 4536 raw_ptr()->data_[index] = value; |
| 4427 } | 4537 } |
| 4428 | 4538 |
| 4539 static const intptr_t kBytesPerElement = 8; |
| 4540 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 4541 |
| 4429 static intptr_t InstanceSize() { | 4542 static intptr_t InstanceSize() { |
| 4430 ASSERT(sizeof(RawFloat64Array) == OFFSET_OF(RawFloat64Array, data_)); | 4543 ASSERT(sizeof(RawFloat64Array) == OFFSET_OF(RawFloat64Array, data_)); |
| 4431 return 0; | 4544 return 0; |
| 4432 } | 4545 } |
| 4433 | 4546 |
| 4434 static intptr_t data_offset() { | 4547 static intptr_t data_offset() { |
| 4435 return length_offset() + kWordSize; | 4548 return length_offset() + kWordSize; |
| 4436 } | 4549 } |
| 4437 | 4550 |
| 4438 static intptr_t InstanceSize(intptr_t len) { | 4551 static intptr_t InstanceSize(intptr_t len) { |
| 4439 intptr_t data_size = len * kBytesPerElement; | 4552 ASSERT(0 <= len && len <= kMaxElements); |
| 4440 return RoundedAllocationSize(sizeof(RawFloat64Array) + data_size); | 4553 return RoundedAllocationSize( |
| 4554 sizeof(RawFloat64Array) + (len * kBytesPerElement)); |
| 4441 } | 4555 } |
| 4442 | 4556 |
| 4443 static RawFloat64Array* New(intptr_t len, | 4557 static RawFloat64Array* New(intptr_t len, |
| 4444 Heap::Space space = Heap::kNew); | 4558 Heap::Space space = Heap::kNew); |
| 4445 static RawFloat64Array* New(const double* data, | 4559 static RawFloat64Array* New(const double* data, |
| 4446 intptr_t len, | 4560 intptr_t len, |
| 4447 Heap::Space space = Heap::kNew); | 4561 Heap::Space space = Heap::kNew); |
| 4448 | 4562 |
| 4449 private: | 4563 private: |
| 4450 static const intptr_t kBytesPerElement = 8; | |
| 4451 | |
| 4452 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4564 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4453 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4565 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4454 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | 4566 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; |
| 4455 } | 4567 } |
| 4456 | 4568 |
| 4457 HEAP_OBJECT_IMPLEMENTATION(Float64Array, ByteArray); | 4569 HEAP_OBJECT_IMPLEMENTATION(Float64Array, ByteArray); |
| 4458 friend class ByteArray; | 4570 friend class ByteArray; |
| 4459 friend class Class; | 4571 friend class Class; |
| 4460 }; | 4572 }; |
| 4461 | 4573 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4473 | 4585 |
| 4474 void SetAt(intptr_t index, int8_t value) const { | 4586 void SetAt(intptr_t index, int8_t value) const { |
| 4475 ASSERT((index >= 0) && (index < Length())); | 4587 ASSERT((index >= 0) && (index < Length())); |
| 4476 raw_ptr()->external_data_->data()[index] = value; | 4588 raw_ptr()->external_data_->data()[index] = value; |
| 4477 } | 4589 } |
| 4478 | 4590 |
| 4479 void* GetPeer() const { | 4591 void* GetPeer() const { |
| 4480 return raw_ptr()->external_data_->peer(); | 4592 return raw_ptr()->external_data_->peer(); |
| 4481 } | 4593 } |
| 4482 | 4594 |
| 4595 static const intptr_t kBytesPerElement = 1; |
| 4596 |
| 4597 // Since external arrays may be serialized to non-external ones, |
| 4598 // enforce the same maximum element count. |
| 4599 static const intptr_t kMaxElements = Int8Array::kMaxElements; |
| 4600 |
| 4483 static intptr_t InstanceSize() { | 4601 static intptr_t InstanceSize() { |
| 4484 return RoundedAllocationSize(sizeof(RawExternalInt8Array)); | 4602 return RoundedAllocationSize(sizeof(RawExternalInt8Array)); |
| 4485 } | 4603 } |
| 4486 | 4604 |
| 4487 static RawExternalInt8Array* New(int8_t* data, | 4605 static RawExternalInt8Array* New(int8_t* data, |
| 4488 intptr_t len, | 4606 intptr_t len, |
| 4489 void* peer, | 4607 void* peer, |
| 4490 Dart_PeerFinalizer callback, | 4608 Dart_PeerFinalizer callback, |
| 4491 Heap::Space space = Heap::kNew); | 4609 Heap::Space space = Heap::kNew); |
| 4492 | 4610 |
| 4493 private: | 4611 private: |
| 4494 static const intptr_t kBytesPerElement = 1; | |
| 4495 | |
| 4496 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4612 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4497 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4613 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4498 uint8_t* data = | 4614 uint8_t* data = |
| 4499 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | 4615 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); |
| 4500 return data + byte_offset; | 4616 return data + byte_offset; |
| 4501 } | 4617 } |
| 4502 | 4618 |
| 4503 void SetExternalData(ExternalByteArrayData<int8_t>* data) { | 4619 void SetExternalData(ExternalByteArrayData<int8_t>* data) { |
| 4504 raw_ptr()->external_data_ = data; | 4620 raw_ptr()->external_data_ = data; |
| 4505 } | 4621 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4523 | 4639 |
| 4524 void SetAt(intptr_t index, uint8_t value) const { | 4640 void SetAt(intptr_t index, uint8_t value) const { |
| 4525 ASSERT((index >= 0) && (index < Length())); | 4641 ASSERT((index >= 0) && (index < Length())); |
| 4526 raw_ptr()->external_data_->data()[index] = value; | 4642 raw_ptr()->external_data_->data()[index] = value; |
| 4527 } | 4643 } |
| 4528 | 4644 |
| 4529 void* GetPeer() const { | 4645 void* GetPeer() const { |
| 4530 return raw_ptr()->external_data_->peer(); | 4646 return raw_ptr()->external_data_->peer(); |
| 4531 } | 4647 } |
| 4532 | 4648 |
| 4649 static const intptr_t kBytesPerElement = 1; |
| 4650 |
| 4651 // Since external arrays may be serialized to non-external ones, |
| 4652 // enforce the same maximum element count. |
| 4653 static const intptr_t kMaxElements = Uint8Array::kMaxElements; |
| 4654 |
| 4533 static intptr_t InstanceSize() { | 4655 static intptr_t InstanceSize() { |
| 4534 return RoundedAllocationSize(sizeof(RawExternalUint8Array)); | 4656 return RoundedAllocationSize(sizeof(RawExternalUint8Array)); |
| 4535 } | 4657 } |
| 4536 | 4658 |
| 4537 static RawExternalUint8Array* New(uint8_t* data, | 4659 static RawExternalUint8Array* New(uint8_t* data, |
| 4538 intptr_t len, | 4660 intptr_t len, |
| 4539 void* peer, | 4661 void* peer, |
| 4540 Dart_PeerFinalizer callback, | 4662 Dart_PeerFinalizer callback, |
| 4541 Heap::Space space = Heap::kNew); | 4663 Heap::Space space = Heap::kNew); |
| 4542 | 4664 |
| 4543 private: | 4665 private: |
| 4544 static const intptr_t kBytesPerElement = 1; | |
| 4545 | |
| 4546 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4666 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4547 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4667 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4548 uint8_t* data = | 4668 uint8_t* data = |
| 4549 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | 4669 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); |
| 4550 return data + byte_offset; | 4670 return data + byte_offset; |
| 4551 } | 4671 } |
| 4552 | 4672 |
| 4553 void SetExternalData(ExternalByteArrayData<uint8_t>* data) { | 4673 void SetExternalData(ExternalByteArrayData<uint8_t>* data) { |
| 4554 raw_ptr()->external_data_ = data; | 4674 raw_ptr()->external_data_ = data; |
| 4555 } | 4675 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4573 | 4693 |
| 4574 void SetAt(intptr_t index, int16_t value) const { | 4694 void SetAt(intptr_t index, int16_t value) const { |
| 4575 ASSERT((index >= 0) && (index < Length())); | 4695 ASSERT((index >= 0) && (index < Length())); |
| 4576 raw_ptr()->external_data_->data()[index] = value; | 4696 raw_ptr()->external_data_->data()[index] = value; |
| 4577 } | 4697 } |
| 4578 | 4698 |
| 4579 void* GetPeer() const { | 4699 void* GetPeer() const { |
| 4580 return raw_ptr()->external_data_->peer(); | 4700 return raw_ptr()->external_data_->peer(); |
| 4581 } | 4701 } |
| 4582 | 4702 |
| 4703 static const intptr_t kBytesPerElement = 2; |
| 4704 |
| 4705 // Since external arrays may be serialized to non-external ones, |
| 4706 // enforce the same maximum element count. |
| 4707 static const intptr_t kMaxElements = Int16Array::kMaxElements; |
| 4708 |
| 4583 static intptr_t InstanceSize() { | 4709 static intptr_t InstanceSize() { |
| 4584 return RoundedAllocationSize(sizeof(RawExternalInt16Array)); | 4710 return RoundedAllocationSize(sizeof(RawExternalInt16Array)); |
| 4585 } | 4711 } |
| 4586 | 4712 |
| 4587 static RawExternalInt16Array* New(int16_t* data, | 4713 static RawExternalInt16Array* New(int16_t* data, |
| 4588 intptr_t len, | 4714 intptr_t len, |
| 4589 void* peer, | 4715 void* peer, |
| 4590 Dart_PeerFinalizer callback, | 4716 Dart_PeerFinalizer callback, |
| 4591 Heap::Space space = Heap::kNew); | 4717 Heap::Space space = Heap::kNew); |
| 4592 | 4718 |
| 4593 private: | 4719 private: |
| 4594 static const intptr_t kBytesPerElement = 2; | |
| 4595 | |
| 4596 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4720 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4597 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4721 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4598 uint8_t* data = | 4722 uint8_t* data = |
| 4599 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | 4723 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); |
| 4600 return data + byte_offset; | 4724 return data + byte_offset; |
| 4601 } | 4725 } |
| 4602 | 4726 |
| 4603 void SetExternalData(ExternalByteArrayData<int16_t>* data) { | 4727 void SetExternalData(ExternalByteArrayData<int16_t>* data) { |
| 4604 raw_ptr()->external_data_ = data; | 4728 raw_ptr()->external_data_ = data; |
| 4605 } | 4729 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4623 | 4747 |
| 4624 void SetAt(intptr_t index, int16_t value) const { | 4748 void SetAt(intptr_t index, int16_t value) const { |
| 4625 ASSERT((index >= 0) && (index < Length())); | 4749 ASSERT((index >= 0) && (index < Length())); |
| 4626 raw_ptr()->external_data_->data()[index] = value; | 4750 raw_ptr()->external_data_->data()[index] = value; |
| 4627 } | 4751 } |
| 4628 | 4752 |
| 4629 void* GetPeer() const { | 4753 void* GetPeer() const { |
| 4630 return raw_ptr()->external_data_->peer(); | 4754 return raw_ptr()->external_data_->peer(); |
| 4631 } | 4755 } |
| 4632 | 4756 |
| 4757 static const intptr_t kBytesPerElement = 2; |
| 4758 |
| 4759 // Since external arrays may be serialized to non-external ones, |
| 4760 // enforce the same maximum element count. |
| 4761 static const intptr_t kMaxElements = Uint16Array::kMaxElements; |
| 4762 |
| 4633 static intptr_t InstanceSize() { | 4763 static intptr_t InstanceSize() { |
| 4634 return RoundedAllocationSize(sizeof(RawExternalUint16Array)); | 4764 return RoundedAllocationSize(sizeof(RawExternalUint16Array)); |
| 4635 } | 4765 } |
| 4636 | 4766 |
| 4637 static RawExternalUint16Array* New(uint16_t* data, | 4767 static RawExternalUint16Array* New(uint16_t* data, |
| 4638 intptr_t len, | 4768 intptr_t len, |
| 4639 void* peer, | 4769 void* peer, |
| 4640 Dart_PeerFinalizer callback, | 4770 Dart_PeerFinalizer callback, |
| 4641 Heap::Space space = Heap::kNew); | 4771 Heap::Space space = Heap::kNew); |
| 4642 | 4772 |
| 4643 private: | 4773 private: |
| 4644 static const intptr_t kBytesPerElement = 2; | |
| 4645 | |
| 4646 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4774 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4647 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4775 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4648 uint8_t* data = | 4776 uint8_t* data = |
| 4649 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | 4777 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); |
| 4650 return data + byte_offset; | 4778 return data + byte_offset; |
| 4651 } | 4779 } |
| 4652 | 4780 |
| 4653 void SetExternalData(ExternalByteArrayData<uint16_t>* data) { | 4781 void SetExternalData(ExternalByteArrayData<uint16_t>* data) { |
| 4654 raw_ptr()->external_data_ = data; | 4782 raw_ptr()->external_data_ = data; |
| 4655 } | 4783 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4673 | 4801 |
| 4674 void SetAt(intptr_t index, int32_t value) const { | 4802 void SetAt(intptr_t index, int32_t value) const { |
| 4675 ASSERT((index >= 0) && (index < Length())); | 4803 ASSERT((index >= 0) && (index < Length())); |
| 4676 raw_ptr()->external_data_->data()[index] = value; | 4804 raw_ptr()->external_data_->data()[index] = value; |
| 4677 } | 4805 } |
| 4678 | 4806 |
| 4679 void* GetPeer() const { | 4807 void* GetPeer() const { |
| 4680 return raw_ptr()->external_data_->peer(); | 4808 return raw_ptr()->external_data_->peer(); |
| 4681 } | 4809 } |
| 4682 | 4810 |
| 4811 static const intptr_t kBytesPerElement = 4; |
| 4812 |
| 4813 // Since external arrays may be serialized to non-external ones, |
| 4814 // enforce the same maximum element count. |
| 4815 static const intptr_t kMaxElements = Int32Array::kMaxElements; |
| 4816 |
| 4683 static intptr_t InstanceSize() { | 4817 static intptr_t InstanceSize() { |
| 4684 return RoundedAllocationSize(sizeof(RawExternalInt32Array)); | 4818 return RoundedAllocationSize(sizeof(RawExternalInt32Array)); |
| 4685 } | 4819 } |
| 4686 | 4820 |
| 4687 static RawExternalInt32Array* New(int32_t* data, | 4821 static RawExternalInt32Array* New(int32_t* data, |
| 4688 intptr_t len, | 4822 intptr_t len, |
| 4689 void* peer, | 4823 void* peer, |
| 4690 Dart_PeerFinalizer callback, | 4824 Dart_PeerFinalizer callback, |
| 4691 Heap::Space space = Heap::kNew); | 4825 Heap::Space space = Heap::kNew); |
| 4692 | 4826 |
| 4693 private: | 4827 private: |
| 4694 static const intptr_t kBytesPerElement = 4; | |
| 4695 | |
| 4696 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4828 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4697 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4829 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4698 uint8_t* data = | 4830 uint8_t* data = |
| 4699 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | 4831 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); |
| 4700 return data + byte_offset; | 4832 return data + byte_offset; |
| 4701 } | 4833 } |
| 4702 | 4834 |
| 4703 void SetExternalData(ExternalByteArrayData<int32_t>* data) { | 4835 void SetExternalData(ExternalByteArrayData<int32_t>* data) { |
| 4704 raw_ptr()->external_data_ = data; | 4836 raw_ptr()->external_data_ = data; |
| 4705 } | 4837 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4723 | 4855 |
| 4724 void SetAt(intptr_t index, int32_t value) const { | 4856 void SetAt(intptr_t index, int32_t value) const { |
| 4725 ASSERT((index >= 0) && (index < Length())); | 4857 ASSERT((index >= 0) && (index < Length())); |
| 4726 raw_ptr()->external_data_->data()[index] = value; | 4858 raw_ptr()->external_data_->data()[index] = value; |
| 4727 } | 4859 } |
| 4728 | 4860 |
| 4729 void* GetPeer() const { | 4861 void* GetPeer() const { |
| 4730 return raw_ptr()->external_data_->peer(); | 4862 return raw_ptr()->external_data_->peer(); |
| 4731 } | 4863 } |
| 4732 | 4864 |
| 4865 static const intptr_t kBytesPerElement = 4; |
| 4866 |
| 4867 // Since external arrays may be serialized to non-external ones, |
| 4868 // enforce the same maximum element count. |
| 4869 static const intptr_t kMaxElements = Uint32Array::kMaxElements; |
| 4870 |
| 4733 static intptr_t InstanceSize() { | 4871 static intptr_t InstanceSize() { |
| 4734 return RoundedAllocationSize(sizeof(RawExternalUint32Array)); | 4872 return RoundedAllocationSize(sizeof(RawExternalUint32Array)); |
| 4735 } | 4873 } |
| 4736 | 4874 |
| 4737 static RawExternalUint32Array* New(uint32_t* data, | 4875 static RawExternalUint32Array* New(uint32_t* data, |
| 4738 intptr_t len, | 4876 intptr_t len, |
| 4739 void* peer, | 4877 void* peer, |
| 4740 Dart_PeerFinalizer callback, | 4878 Dart_PeerFinalizer callback, |
| 4741 Heap::Space space = Heap::kNew); | 4879 Heap::Space space = Heap::kNew); |
| 4742 | 4880 |
| 4743 private: | 4881 private: |
| 4744 static const intptr_t kBytesPerElement = 4; | |
| 4745 | |
| 4746 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4882 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4747 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4883 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4748 uint8_t* data = | 4884 uint8_t* data = |
| 4749 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | 4885 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); |
| 4750 return data + byte_offset; | 4886 return data + byte_offset; |
| 4751 } | 4887 } |
| 4752 | 4888 |
| 4753 void SetExternalData(ExternalByteArrayData<uint32_t>* data) { | 4889 void SetExternalData(ExternalByteArrayData<uint32_t>* data) { |
| 4754 raw_ptr()->external_data_ = data; | 4890 raw_ptr()->external_data_ = data; |
| 4755 } | 4891 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4773 | 4909 |
| 4774 void SetAt(intptr_t index, int64_t value) const { | 4910 void SetAt(intptr_t index, int64_t value) const { |
| 4775 ASSERT((index >= 0) && (index < Length())); | 4911 ASSERT((index >= 0) && (index < Length())); |
| 4776 raw_ptr()->external_data_->data()[index] = value; | 4912 raw_ptr()->external_data_->data()[index] = value; |
| 4777 } | 4913 } |
| 4778 | 4914 |
| 4779 void* GetPeer() const { | 4915 void* GetPeer() const { |
| 4780 return raw_ptr()->external_data_->peer(); | 4916 return raw_ptr()->external_data_->peer(); |
| 4781 } | 4917 } |
| 4782 | 4918 |
| 4919 static const intptr_t kBytesPerElement = 8; |
| 4920 |
| 4921 // Since external arrays may be serialized to non-external ones, |
| 4922 // enforce the same maximum element count. |
| 4923 static const intptr_t kMaxElements = Int64Array::kMaxElements; |
| 4924 |
| 4783 static intptr_t InstanceSize() { | 4925 static intptr_t InstanceSize() { |
| 4784 return RoundedAllocationSize(sizeof(RawExternalInt64Array)); | 4926 return RoundedAllocationSize(sizeof(RawExternalInt64Array)); |
| 4785 } | 4927 } |
| 4786 | 4928 |
| 4787 static RawExternalInt64Array* New(int64_t* data, | 4929 static RawExternalInt64Array* New(int64_t* data, |
| 4788 intptr_t len, | 4930 intptr_t len, |
| 4789 void* peer, | 4931 void* peer, |
| 4790 Dart_PeerFinalizer callback, | 4932 Dart_PeerFinalizer callback, |
| 4791 Heap::Space space = Heap::kNew); | 4933 Heap::Space space = Heap::kNew); |
| 4792 | 4934 |
| 4793 private: | 4935 private: |
| 4794 static const intptr_t kBytesPerElement = 8; | |
| 4795 | |
| 4796 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4936 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4797 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4937 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4798 uint8_t* data = | 4938 uint8_t* data = |
| 4799 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | 4939 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); |
| 4800 return data + byte_offset; | 4940 return data + byte_offset; |
| 4801 } | 4941 } |
| 4802 | 4942 |
| 4803 void SetExternalData(ExternalByteArrayData<int64_t>* data) { | 4943 void SetExternalData(ExternalByteArrayData<int64_t>* data) { |
| 4804 raw_ptr()->external_data_ = data; | 4944 raw_ptr()->external_data_ = data; |
| 4805 } | 4945 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4823 | 4963 |
| 4824 void SetAt(intptr_t index, int64_t value) const { | 4964 void SetAt(intptr_t index, int64_t value) const { |
| 4825 ASSERT((index >= 0) && (index < Length())); | 4965 ASSERT((index >= 0) && (index < Length())); |
| 4826 raw_ptr()->external_data_->data()[index] = value; | 4966 raw_ptr()->external_data_->data()[index] = value; |
| 4827 } | 4967 } |
| 4828 | 4968 |
| 4829 void* GetPeer() const { | 4969 void* GetPeer() const { |
| 4830 return raw_ptr()->external_data_->peer(); | 4970 return raw_ptr()->external_data_->peer(); |
| 4831 } | 4971 } |
| 4832 | 4972 |
| 4973 static const intptr_t kBytesPerElement = 8; |
| 4974 |
| 4975 // Since external arrays may be serialized to non-external ones, |
| 4976 // enforce the same maximum element count. |
| 4977 static const intptr_t kMaxElements = Uint64Array::kMaxElements; |
| 4978 |
| 4833 static intptr_t InstanceSize() { | 4979 static intptr_t InstanceSize() { |
| 4834 return RoundedAllocationSize(sizeof(RawExternalUint64Array)); | 4980 return RoundedAllocationSize(sizeof(RawExternalUint64Array)); |
| 4835 } | 4981 } |
| 4836 | 4982 |
| 4837 static RawExternalUint64Array* New(uint64_t* data, | 4983 static RawExternalUint64Array* New(uint64_t* data, |
| 4838 intptr_t len, | 4984 intptr_t len, |
| 4839 void* peer, | 4985 void* peer, |
| 4840 Dart_PeerFinalizer callback, | 4986 Dart_PeerFinalizer callback, |
| 4841 Heap::Space space = Heap::kNew); | 4987 Heap::Space space = Heap::kNew); |
| 4842 | 4988 |
| 4843 private: | 4989 private: |
| 4844 static const intptr_t kBytesPerElement = 8; | |
| 4845 | |
| 4846 uint8_t* ByteAddr(intptr_t byte_offset) const { | 4990 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4847 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 4991 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4848 uint8_t* data = | 4992 uint8_t* data = |
| 4849 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | 4993 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); |
| 4850 return data + byte_offset; | 4994 return data + byte_offset; |
| 4851 } | 4995 } |
| 4852 | 4996 |
| 4853 void SetExternalData(ExternalByteArrayData<uint64_t>* data) { | 4997 void SetExternalData(ExternalByteArrayData<uint64_t>* data) { |
| 4854 raw_ptr()->external_data_ = data; | 4998 raw_ptr()->external_data_ = data; |
| 4855 } | 4999 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4873 | 5017 |
| 4874 void SetAt(intptr_t index, float value) const { | 5018 void SetAt(intptr_t index, float value) const { |
| 4875 ASSERT((index >= 0) && (index < Length())); | 5019 ASSERT((index >= 0) && (index < Length())); |
| 4876 raw_ptr()->external_data_->data()[index] = value; | 5020 raw_ptr()->external_data_->data()[index] = value; |
| 4877 } | 5021 } |
| 4878 | 5022 |
| 4879 void* GetPeer() const { | 5023 void* GetPeer() const { |
| 4880 return raw_ptr()->external_data_->peer(); | 5024 return raw_ptr()->external_data_->peer(); |
| 4881 } | 5025 } |
| 4882 | 5026 |
| 5027 static const intptr_t kBytesPerElement = 4; |
| 5028 |
| 5029 // Since external arrays may be serialized to non-external ones, |
| 5030 // enforce the same maximum element count. |
| 5031 static const intptr_t kMaxElements = Float32Array::kMaxElements; |
| 5032 |
| 4883 static intptr_t InstanceSize() { | 5033 static intptr_t InstanceSize() { |
| 4884 return RoundedAllocationSize(sizeof(RawExternalFloat32Array)); | 5034 return RoundedAllocationSize(sizeof(RawExternalFloat32Array)); |
| 4885 } | 5035 } |
| 4886 | 5036 |
| 4887 static RawExternalFloat32Array* New(float* data, | 5037 static RawExternalFloat32Array* New(float* data, |
| 4888 intptr_t len, | 5038 intptr_t len, |
| 4889 void* peer, | 5039 void* peer, |
| 4890 Dart_PeerFinalizer callback, | 5040 Dart_PeerFinalizer callback, |
| 4891 Heap::Space space = Heap::kNew); | 5041 Heap::Space space = Heap::kNew); |
| 4892 | 5042 |
| 4893 private: | 5043 private: |
| 4894 static const intptr_t kBytesPerElement = 4; | |
| 4895 | |
| 4896 uint8_t* ByteAddr(intptr_t byte_offset) const { | 5044 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4897 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5045 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4898 uint8_t* data = | 5046 uint8_t* data = |
| 4899 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | 5047 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); |
| 4900 return data + byte_offset; | 5048 return data + byte_offset; |
| 4901 } | 5049 } |
| 4902 | 5050 |
| 4903 void SetExternalData(ExternalByteArrayData<float>* data) { | 5051 void SetExternalData(ExternalByteArrayData<float>* data) { |
| 4904 raw_ptr()->external_data_ = data; | 5052 raw_ptr()->external_data_ = data; |
| 4905 } | 5053 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4923 | 5071 |
| 4924 void SetAt(intptr_t index, double value) const { | 5072 void SetAt(intptr_t index, double value) const { |
| 4925 ASSERT((index >= 0) && (index < Length())); | 5073 ASSERT((index >= 0) && (index < Length())); |
| 4926 raw_ptr()->external_data_->data()[index] = value; | 5074 raw_ptr()->external_data_->data()[index] = value; |
| 4927 } | 5075 } |
| 4928 | 5076 |
| 4929 void* GetPeer() const { | 5077 void* GetPeer() const { |
| 4930 return raw_ptr()->external_data_->peer(); | 5078 return raw_ptr()->external_data_->peer(); |
| 4931 } | 5079 } |
| 4932 | 5080 |
| 5081 static const intptr_t kBytesPerElement = 8; |
| 5082 |
| 5083 // Since external arrays may be serialized to non-external ones, |
| 5084 // enforce the same maximum element count. |
| 5085 static const intptr_t kMaxElements = Float64Array::kMaxElements; |
| 5086 |
| 4933 static intptr_t InstanceSize() { | 5087 static intptr_t InstanceSize() { |
| 4934 return RoundedAllocationSize(sizeof(RawExternalFloat64Array)); | 5088 return RoundedAllocationSize(sizeof(RawExternalFloat64Array)); |
| 4935 } | 5089 } |
| 4936 | 5090 |
| 4937 static RawExternalFloat64Array* New(double* data, | 5091 static RawExternalFloat64Array* New(double* data, |
| 4938 intptr_t len, | 5092 intptr_t len, |
| 4939 void* peer, | 5093 void* peer, |
| 4940 Dart_PeerFinalizer callback, | 5094 Dart_PeerFinalizer callback, |
| 4941 Heap::Space space = Heap::kNew); | 5095 Heap::Space space = Heap::kNew); |
| 4942 | 5096 |
| 4943 private: | 5097 private: |
| 4944 static const intptr_t kBytesPerElement = 8; | |
| 4945 | |
| 4946 uint8_t* ByteAddr(intptr_t byte_offset) const { | 5098 uint8_t* ByteAddr(intptr_t byte_offset) const { |
| 4947 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | 5099 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); |
| 4948 uint8_t* data = | 5100 uint8_t* data = |
| 4949 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); | 5101 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data()); |
| 4950 return data + byte_offset; | 5102 return data + byte_offset; |
| 4951 } | 5103 } |
| 4952 | 5104 |
| 4953 void SetExternalData(ExternalByteArrayData<double>* data) { | 5105 void SetExternalData(ExternalByteArrayData<double>* data) { |
| 4954 raw_ptr()->external_data_ = data; | 5106 raw_ptr()->external_data_ = data; |
| 4955 } | 5107 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5075 void set_is_multi_line() const { raw_ptr()->flags_ |= kMultiLine; } | 5227 void set_is_multi_line() const { raw_ptr()->flags_ |= kMultiLine; } |
| 5076 void set_is_simple() const { raw_ptr()->type_ = kSimple; } | 5228 void set_is_simple() const { raw_ptr()->type_ = kSimple; } |
| 5077 void set_is_complex() const { raw_ptr()->type_ = kComplex; } | 5229 void set_is_complex() const { raw_ptr()->type_ = kComplex; } |
| 5078 | 5230 |
| 5079 void* GetDataStartAddress() const; | 5231 void* GetDataStartAddress() const; |
| 5080 static RawJSRegExp* FromDataStartAddress(void* data); | 5232 static RawJSRegExp* FromDataStartAddress(void* data); |
| 5081 const char* Flags() const; | 5233 const char* Flags() const; |
| 5082 | 5234 |
| 5083 virtual bool Equals(const Instance& other) const; | 5235 virtual bool Equals(const Instance& other) const; |
| 5084 | 5236 |
| 5237 static const intptr_t kBytesPerElement = 1; |
| 5238 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; |
| 5239 |
| 5085 static intptr_t InstanceSize() { | 5240 static intptr_t InstanceSize() { |
| 5086 ASSERT(sizeof(RawJSRegExp) == OFFSET_OF(RawJSRegExp, data_)); | 5241 ASSERT(sizeof(RawJSRegExp) == OFFSET_OF(RawJSRegExp, data_)); |
| 5087 return 0; | 5242 return 0; |
| 5088 } | 5243 } |
| 5089 | 5244 |
| 5090 static intptr_t InstanceSize(intptr_t len) { | 5245 static intptr_t InstanceSize(intptr_t len) { |
| 5091 return RoundedAllocationSize(sizeof(RawJSRegExp) + len); | 5246 ASSERT(0 <= len && len <= kMaxElements); |
| 5247 return RoundedAllocationSize( |
| 5248 sizeof(RawJSRegExp) + (len * kBytesPerElement)); |
| 5092 } | 5249 } |
| 5093 | 5250 |
| 5094 static RawJSRegExp* New(intptr_t length, Heap::Space space = Heap::kNew); | 5251 static RawJSRegExp* New(intptr_t length, Heap::Space space = Heap::kNew); |
| 5095 | 5252 |
| 5096 private: | 5253 private: |
| 5097 void set_type(RegExType type) const { raw_ptr()->type_ = type; } | 5254 void set_type(RegExType type) const { raw_ptr()->type_ = type; } |
| 5098 void set_flags(intptr_t value) const { raw_ptr()->flags_ = value; } | 5255 void set_flags(intptr_t value) const { raw_ptr()->flags_ = value; } |
| 5099 | 5256 |
| 5100 void SetLength(intptr_t value) const { | 5257 void SetLength(intptr_t value) const { |
| 5101 // This is only safe because we create a new Smi, which does not cause | 5258 // This is only safe because we create a new Smi, which does not cause |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5212 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5369 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
| 5213 return false; | 5370 return false; |
| 5214 } | 5371 } |
| 5215 } | 5372 } |
| 5216 return true; | 5373 return true; |
| 5217 } | 5374 } |
| 5218 | 5375 |
| 5219 } // namespace dart | 5376 } // namespace dart |
| 5220 | 5377 |
| 5221 #endif // VM_OBJECT_H_ | 5378 #endif // VM_OBJECT_H_ |
| OLD | NEW |