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 2164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2175 static RawLibrary* AsyncLibrary(); | 2175 static RawLibrary* AsyncLibrary(); |
2176 static RawLibrary* CoreLibrary(); | 2176 static RawLibrary* CoreLibrary(); |
2177 static RawLibrary* CollectionLibrary(); | 2177 static RawLibrary* CollectionLibrary(); |
2178 static RawLibrary* CollectionDevLibrary(); | 2178 static RawLibrary* CollectionDevLibrary(); |
2179 static RawLibrary* CryptoLibrary(); | 2179 static RawLibrary* CryptoLibrary(); |
2180 static RawLibrary* IsolateLibrary(); | 2180 static RawLibrary* IsolateLibrary(); |
2181 static RawLibrary* JsonLibrary(); | 2181 static RawLibrary* JsonLibrary(); |
2182 static RawLibrary* MathLibrary(); | 2182 static RawLibrary* MathLibrary(); |
2183 static RawLibrary* MirrorsLibrary(); | 2183 static RawLibrary* MirrorsLibrary(); |
2184 static RawLibrary* NativeWrappersLibrary(); | 2184 static RawLibrary* NativeWrappersLibrary(); |
2185 static RawLibrary* ScalarlistLibrary(); | |
2186 static RawLibrary* TypedDataLibrary(); | 2185 static RawLibrary* TypedDataLibrary(); |
2187 static RawLibrary* UriLibrary(); | 2186 static RawLibrary* UriLibrary(); |
2188 static RawLibrary* UtfLibrary(); | 2187 static RawLibrary* UtfLibrary(); |
2189 | 2188 |
2190 // Eagerly compile all classes and functions in the library. | 2189 // Eagerly compile all classes and functions in the library. |
2191 static RawError* CompileAll(); | 2190 static RawError* CompileAll(); |
2192 | 2191 |
2193 private: | 2192 private: |
2194 static const int kInitialImportsCapacity = 4; | 2193 static const int kInitialImportsCapacity = 4; |
2195 static const int kImportsCapacityIncrement = 8; | 2194 static const int kImportsCapacityIncrement = 8; |
(...skipping 3002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5198 void SetPeer(void* peer) const { | 5197 void SetPeer(void* peer) const { |
5199 raw_ptr()->peer_ = peer; | 5198 raw_ptr()->peer_ = peer; |
5200 } | 5199 } |
5201 | 5200 |
5202 private: | 5201 private: |
5203 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData, Instance); | 5202 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData, Instance); |
5204 friend class Class; | 5203 friend class Class; |
5205 }; | 5204 }; |
5206 | 5205 |
5207 | 5206 |
5208 class ByteArray : public Instance { | |
5209 public: | |
5210 intptr_t Length() const { | |
5211 ASSERT(!IsNull()); | |
5212 return Smi::Value(raw_ptr()->length_); | |
5213 } | |
5214 | |
5215 static intptr_t length_offset() { | |
5216 return OFFSET_OF(RawByteArray, length_); | |
5217 } | |
5218 | |
5219 virtual intptr_t ByteLength() const; | |
5220 | |
5221 virtual void* GetPeer() const { return NULL; } | |
5222 virtual uint8_t* ByteAddr(intptr_t byte_offset) const; | |
5223 | |
5224 FinalizablePersistentHandle* AddFinalizer( | |
5225 void* peer, Dart_WeakPersistentHandleFinalizer callback) const; | |
5226 | |
5227 static void Copy(void* dst, | |
5228 const ByteArray& src, | |
5229 intptr_t src_offset, | |
5230 intptr_t length); | |
5231 | |
5232 static void Copy(const ByteArray& dst, | |
5233 intptr_t dst_offset, | |
5234 const void* src, | |
5235 intptr_t length); | |
5236 | |
5237 static void Copy(const ByteArray& dst, | |
5238 intptr_t dst_offset, | |
5239 const ByteArray& src, | |
5240 intptr_t src_offset, | |
5241 intptr_t length); | |
5242 | |
5243 protected: | |
5244 virtual void SetPeer(void* peer) const { } | |
5245 | |
5246 template<typename HandleT, typename RawT> | |
5247 static RawT* NewImpl(intptr_t class_id, | |
5248 intptr_t len, | |
5249 Heap::Space space); | |
5250 | |
5251 template<typename HandleT, typename RawT, typename ElementT> | |
5252 static RawT* NewImpl(intptr_t class_id, | |
5253 const ElementT* data, | |
5254 intptr_t len, | |
5255 Heap::Space space); | |
5256 | |
5257 template<typename HandleT, typename RawT, typename ElementT> | |
5258 static RawT* NewExternalImpl(intptr_t class_id, | |
5259 ElementT* data, | |
5260 intptr_t len, | |
5261 Heap::Space space); | |
5262 | |
5263 template<typename HandleT, typename RawT, typename ElementT> | |
5264 static RawT* ReadFromImpl(SnapshotReader* reader, | |
5265 intptr_t object_id, | |
5266 intptr_t tags, | |
5267 Snapshot::Kind kind); | |
5268 | |
5269 void SetLength(intptr_t value) const { | |
5270 raw_ptr()->length_ = Smi::New(value); | |
5271 } | |
5272 | |
5273 private: | |
5274 HEAP_OBJECT_IMPLEMENTATION(ByteArray, Instance); | |
5275 friend class Class; | |
5276 }; | |
5277 | |
5278 | |
5279 class Int8Array : public ByteArray { | |
5280 public: | |
5281 intptr_t ByteLength() const { | |
5282 return Length(); | |
5283 } | |
5284 | |
5285 int8_t At(intptr_t index) const { | |
5286 ASSERT((index >= 0) && (index < Length())); | |
5287 return raw_ptr()->data_[index]; | |
5288 } | |
5289 | |
5290 void SetAt(intptr_t index, int8_t value) const { | |
5291 ASSERT((index >= 0) && (index < Length())); | |
5292 raw_ptr()->data_[index] = value; | |
5293 } | |
5294 | |
5295 static const intptr_t kBytesPerElement = 1; | |
5296 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | |
5297 | |
5298 static intptr_t data_offset() { | |
5299 return OFFSET_OF(RawInt8Array, data_); | |
5300 } | |
5301 | |
5302 static intptr_t InstanceSize() { | |
5303 ASSERT(sizeof(RawInt8Array) == OFFSET_OF(RawInt8Array, data_)); | |
5304 return 0; | |
5305 } | |
5306 | |
5307 static intptr_t InstanceSize(intptr_t len) { | |
5308 ASSERT(0 <= len && len <= kMaxElements); | |
5309 return RoundedAllocationSize( | |
5310 sizeof(RawInt8Array) + (len * kBytesPerElement)); | |
5311 } | |
5312 | |
5313 static RawInt8Array* New(intptr_t len, | |
5314 Heap::Space space = Heap::kNew); | |
5315 static RawInt8Array* New(const int8_t* data, | |
5316 intptr_t len, | |
5317 Heap::Space space = Heap::kNew); | |
5318 | |
5319 private: | |
5320 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
5321 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
5322 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
5323 } | |
5324 | |
5325 FINAL_HEAP_OBJECT_IMPLEMENTATION(Int8Array, ByteArray); | |
5326 friend class ByteArray; | |
5327 friend class Class; | |
5328 }; | |
5329 | |
5330 | |
5331 class Uint8Array : public ByteArray { | |
5332 public: | |
5333 intptr_t ByteLength() const { | |
5334 return Length(); | |
5335 } | |
5336 | |
5337 uint8_t At(intptr_t index) const { | |
5338 ASSERT((index >= 0) && (index < Length())); | |
5339 return raw_ptr()->data_[index]; | |
5340 } | |
5341 | |
5342 void SetAt(intptr_t index, uint8_t value) const { | |
5343 ASSERT((index >= 0) && (index < Length())); | |
5344 raw_ptr()->data_[index] = value; | |
5345 } | |
5346 | |
5347 static const intptr_t kBytesPerElement = 1; | |
5348 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | |
5349 | |
5350 static intptr_t data_offset() { | |
5351 return OFFSET_OF(RawUint8Array, data_); | |
5352 } | |
5353 | |
5354 static intptr_t InstanceSize() { | |
5355 ASSERT(sizeof(RawUint8Array) == OFFSET_OF(RawUint8Array, data_)); | |
5356 return 0; | |
5357 } | |
5358 | |
5359 static intptr_t InstanceSize(intptr_t len) { | |
5360 ASSERT(0 <= len && len <= kMaxElements); | |
5361 return RoundedAllocationSize( | |
5362 sizeof(RawUint8Array) + (len * kBytesPerElement)); | |
5363 } | |
5364 | |
5365 static RawUint8Array* New(intptr_t len, | |
5366 Heap::Space space = Heap::kNew); | |
5367 static RawUint8Array* New(const uint8_t* data, | |
5368 intptr_t len, | |
5369 Heap::Space space = Heap::kNew); | |
5370 | |
5371 private: | |
5372 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
5373 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
5374 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
5375 } | |
5376 | |
5377 FINAL_HEAP_OBJECT_IMPLEMENTATION(Uint8Array, ByteArray); | |
5378 friend class ByteArray; | |
5379 friend class Class; | |
5380 }; | |
5381 | |
5382 | |
5383 class Uint8ClampedArray : public ByteArray { | |
5384 public: | |
5385 intptr_t ByteLength() const { | |
5386 return Length(); | |
5387 } | |
5388 | |
5389 uint8_t At(intptr_t index) const { | |
5390 ASSERT((index >= 0) && (index < Length())); | |
5391 return raw_ptr()->data_[index]; | |
5392 } | |
5393 | |
5394 void SetAt(intptr_t index, uint8_t value) const { | |
5395 ASSERT((index >= 0) && (index < Length())); | |
5396 raw_ptr()->data_[index] = value; | |
5397 } | |
5398 | |
5399 static const intptr_t kBytesPerElement = 1; | |
5400 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | |
5401 | |
5402 static intptr_t data_offset() { | |
5403 return OFFSET_OF(RawUint8ClampedArray, data_); | |
5404 } | |
5405 | |
5406 static intptr_t InstanceSize() { | |
5407 ASSERT(sizeof(RawUint8ClampedArray) == | |
5408 OFFSET_OF(RawUint8ClampedArray, data_)); | |
5409 return 0; | |
5410 } | |
5411 | |
5412 static intptr_t InstanceSize(intptr_t len) { | |
5413 ASSERT(0 <= len && len <= kMaxElements); | |
5414 return RoundedAllocationSize( | |
5415 sizeof(RawUint8ClampedArray) + (len * kBytesPerElement)); | |
5416 } | |
5417 | |
5418 static RawUint8ClampedArray* New(intptr_t len, | |
5419 Heap::Space space = Heap::kNew); | |
5420 static RawUint8ClampedArray* New(const uint8_t* data, | |
5421 intptr_t len, | |
5422 Heap::Space space = Heap::kNew); | |
5423 | |
5424 private: | |
5425 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
5426 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
5427 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
5428 } | |
5429 | |
5430 FINAL_HEAP_OBJECT_IMPLEMENTATION(Uint8ClampedArray, ByteArray); | |
5431 friend class ByteArray; | |
5432 friend class Class; | |
5433 }; | |
5434 | |
5435 | |
5436 class Int16Array : public ByteArray { | |
5437 public: | |
5438 intptr_t ByteLength() const { | |
5439 return Length() * kBytesPerElement; | |
5440 } | |
5441 | |
5442 int16_t At(intptr_t index) const { | |
5443 ASSERT((index >= 0) && (index < Length())); | |
5444 return raw_ptr()->data_[index]; | |
5445 } | |
5446 | |
5447 void SetAt(intptr_t index, int16_t value) const { | |
5448 ASSERT((index >= 0) && (index < Length())); | |
5449 raw_ptr()->data_[index] = value; | |
5450 } | |
5451 | |
5452 static const intptr_t kBytesPerElement = 2; | |
5453 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | |
5454 | |
5455 static intptr_t data_offset() { | |
5456 return OFFSET_OF(RawInt16Array, data_); | |
5457 } | |
5458 | |
5459 static intptr_t InstanceSize() { | |
5460 ASSERT(sizeof(RawInt16Array) == OFFSET_OF(RawInt16Array, data_)); | |
5461 return 0; | |
5462 } | |
5463 | |
5464 static intptr_t InstanceSize(intptr_t len) { | |
5465 ASSERT(0 <= len && len <= kMaxElements); | |
5466 return RoundedAllocationSize( | |
5467 sizeof(RawInt16Array) + (len * kBytesPerElement)); | |
5468 } | |
5469 | |
5470 static RawInt16Array* New(intptr_t len, | |
5471 Heap::Space space = Heap::kNew); | |
5472 static RawInt16Array* New(const int16_t* data, | |
5473 intptr_t len, | |
5474 Heap::Space space = Heap::kNew); | |
5475 | |
5476 private: | |
5477 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
5478 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
5479 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
5480 } | |
5481 | |
5482 FINAL_HEAP_OBJECT_IMPLEMENTATION(Int16Array, ByteArray); | |
5483 friend class ByteArray; | |
5484 friend class Class; | |
5485 }; | |
5486 | |
5487 | |
5488 class Uint16Array : public ByteArray { | |
5489 public: | |
5490 intptr_t ByteLength() const { | |
5491 return Length() * kBytesPerElement; | |
5492 } | |
5493 | |
5494 uint16_t At(intptr_t index) const { | |
5495 ASSERT((index >= 0) && (index < Length())); | |
5496 return raw_ptr()->data_[index]; | |
5497 } | |
5498 | |
5499 void SetAt(intptr_t index, uint16_t value) const { | |
5500 ASSERT((index >= 0) && (index < Length())); | |
5501 raw_ptr()->data_[index] = value; | |
5502 } | |
5503 | |
5504 static const intptr_t kBytesPerElement = 2; | |
5505 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | |
5506 | |
5507 static intptr_t data_offset() { | |
5508 return OFFSET_OF(RawUint16Array, data_); | |
5509 } | |
5510 | |
5511 static intptr_t InstanceSize() { | |
5512 ASSERT(sizeof(RawUint16Array) == OFFSET_OF(RawUint16Array, data_)); | |
5513 return 0; | |
5514 } | |
5515 | |
5516 static intptr_t InstanceSize(intptr_t len) { | |
5517 ASSERT(0 <= len && len <= kMaxElements); | |
5518 return RoundedAllocationSize( | |
5519 sizeof(RawUint16Array) + (len * kBytesPerElement)); | |
5520 } | |
5521 | |
5522 static RawUint16Array* New(intptr_t len, | |
5523 Heap::Space space = Heap::kNew); | |
5524 static RawUint16Array* New(const uint16_t* data, | |
5525 intptr_t len, | |
5526 Heap::Space space = Heap::kNew); | |
5527 | |
5528 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
5529 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
5530 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
5531 } | |
5532 | |
5533 private: | |
5534 FINAL_HEAP_OBJECT_IMPLEMENTATION(Uint16Array, ByteArray); | |
5535 friend class ByteArray; | |
5536 friend class Class; | |
5537 }; | |
5538 | |
5539 | |
5540 class Int32Array : public ByteArray { | |
5541 public: | |
5542 intptr_t ByteLength() const { | |
5543 return Length() * kBytesPerElement; | |
5544 } | |
5545 | |
5546 int32_t At(intptr_t index) const { | |
5547 ASSERT((index >= 0) && (index < Length())); | |
5548 return raw_ptr()->data_[index]; | |
5549 } | |
5550 | |
5551 void SetAt(intptr_t index, int32_t value) const { | |
5552 ASSERT((index >= 0) && (index < Length())); | |
5553 raw_ptr()->data_[index] = value; | |
5554 } | |
5555 | |
5556 static const intptr_t kBytesPerElement = 4; | |
5557 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | |
5558 | |
5559 static intptr_t data_offset() { | |
5560 return OFFSET_OF(RawInt32Array, data_); | |
5561 } | |
5562 | |
5563 static intptr_t InstanceSize() { | |
5564 ASSERT(sizeof(RawInt32Array) == OFFSET_OF(RawInt32Array, data_)); | |
5565 return 0; | |
5566 } | |
5567 | |
5568 static intptr_t InstanceSize(intptr_t len) { | |
5569 ASSERT(0 <= len && len <= kMaxElements); | |
5570 return RoundedAllocationSize( | |
5571 sizeof(RawInt32Array) + (len * kBytesPerElement)); | |
5572 } | |
5573 | |
5574 static RawInt32Array* New(intptr_t len, | |
5575 Heap::Space space = Heap::kNew); | |
5576 static RawInt32Array* New(const int32_t* data, | |
5577 intptr_t len, | |
5578 Heap::Space space = Heap::kNew); | |
5579 | |
5580 private: | |
5581 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
5582 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
5583 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
5584 } | |
5585 | |
5586 FINAL_HEAP_OBJECT_IMPLEMENTATION(Int32Array, ByteArray); | |
5587 friend class ByteArray; | |
5588 friend class Class; | |
5589 }; | |
5590 | |
5591 | |
5592 class Uint32Array : public ByteArray { | |
5593 public: | |
5594 intptr_t ByteLength() const { | |
5595 return Length() * kBytesPerElement; | |
5596 } | |
5597 | |
5598 uint32_t At(intptr_t index) const { | |
5599 ASSERT((index >= 0) && (index < Length())); | |
5600 return raw_ptr()->data_[index]; | |
5601 } | |
5602 | |
5603 void SetAt(intptr_t index, uint32_t value) const { | |
5604 ASSERT((index >= 0) && (index < Length())); | |
5605 raw_ptr()->data_[index] = value; | |
5606 } | |
5607 | |
5608 static const intptr_t kBytesPerElement = 4; | |
5609 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | |
5610 | |
5611 static intptr_t data_offset() { | |
5612 return OFFSET_OF(RawUint32Array, data_); | |
5613 } | |
5614 | |
5615 static intptr_t InstanceSize() { | |
5616 ASSERT(sizeof(RawUint32Array) == OFFSET_OF(RawUint32Array, data_)); | |
5617 return 0; | |
5618 } | |
5619 | |
5620 static intptr_t InstanceSize(intptr_t len) { | |
5621 ASSERT(0 <= len && len <= kMaxElements); | |
5622 return RoundedAllocationSize( | |
5623 sizeof(RawUint32Array) + (len * kBytesPerElement)); | |
5624 } | |
5625 | |
5626 static RawUint32Array* New(intptr_t len, | |
5627 Heap::Space space = Heap::kNew); | |
5628 static RawUint32Array* New(const uint32_t* data, | |
5629 intptr_t len, | |
5630 Heap::Space space = Heap::kNew); | |
5631 | |
5632 private: | |
5633 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
5634 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
5635 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
5636 } | |
5637 | |
5638 FINAL_HEAP_OBJECT_IMPLEMENTATION(Uint32Array, ByteArray); | |
5639 friend class ByteArray; | |
5640 friend class Class; | |
5641 }; | |
5642 | |
5643 | |
5644 class Int64Array : public ByteArray { | |
5645 public: | |
5646 intptr_t ByteLength() const { | |
5647 return Length() * kBytesPerElement; | |
5648 } | |
5649 | |
5650 int64_t At(intptr_t index) const { | |
5651 ASSERT((index >= 0) && (index < Length())); | |
5652 return raw_ptr()->data_[index]; | |
5653 } | |
5654 | |
5655 void SetAt(intptr_t index, int64_t value) const { | |
5656 ASSERT((index >= 0) && (index < Length())); | |
5657 raw_ptr()->data_[index] = value; | |
5658 } | |
5659 | |
5660 static const intptr_t kBytesPerElement = 8; | |
5661 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | |
5662 | |
5663 static intptr_t data_offset() { | |
5664 return OFFSET_OF(RawInt64Array, data_); | |
5665 } | |
5666 | |
5667 static intptr_t InstanceSize() { | |
5668 ASSERT(sizeof(RawInt64Array) == OFFSET_OF(RawInt64Array, data_)); | |
5669 return 0; | |
5670 } | |
5671 | |
5672 static intptr_t InstanceSize(intptr_t len) { | |
5673 ASSERT(0 <= len && len <= kMaxElements); | |
5674 return RoundedAllocationSize( | |
5675 sizeof(RawInt64Array) + (len * kBytesPerElement)); | |
5676 } | |
5677 | |
5678 static RawInt64Array* New(intptr_t len, | |
5679 Heap::Space space = Heap::kNew); | |
5680 static RawInt64Array* New(const int64_t* data, | |
5681 intptr_t len, | |
5682 Heap::Space space = Heap::kNew); | |
5683 | |
5684 private: | |
5685 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
5686 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
5687 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
5688 } | |
5689 | |
5690 FINAL_HEAP_OBJECT_IMPLEMENTATION(Int64Array, ByteArray); | |
5691 friend class ByteArray; | |
5692 friend class Class; | |
5693 }; | |
5694 | |
5695 | |
5696 class Uint64Array : public ByteArray { | |
5697 public: | |
5698 intptr_t ByteLength() const { | |
5699 return Length() * sizeof(uint64_t); | |
5700 } | |
5701 | |
5702 uint64_t At(intptr_t index) const { | |
5703 ASSERT((index >= 0) && (index < Length())); | |
5704 return raw_ptr()->data_[index]; | |
5705 } | |
5706 | |
5707 void SetAt(intptr_t index, uint64_t value) const { | |
5708 ASSERT((index >= 0) && (index < Length())); | |
5709 raw_ptr()->data_[index] = value; | |
5710 } | |
5711 | |
5712 static const intptr_t kBytesPerElement = 8; | |
5713 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | |
5714 | |
5715 static intptr_t data_offset() { | |
5716 return OFFSET_OF(RawUint64Array, data_); | |
5717 } | |
5718 | |
5719 static intptr_t InstanceSize() { | |
5720 ASSERT(sizeof(RawUint64Array) == OFFSET_OF(RawUint64Array, data_)); | |
5721 return 0; | |
5722 } | |
5723 | |
5724 static intptr_t InstanceSize(intptr_t len) { | |
5725 ASSERT(0 <= len && len <= kMaxElements); | |
5726 return RoundedAllocationSize( | |
5727 sizeof(RawUint64Array) + (len * kBytesPerElement)); | |
5728 } | |
5729 | |
5730 static RawUint64Array* New(intptr_t len, | |
5731 Heap::Space space = Heap::kNew); | |
5732 static RawUint64Array* New(const uint64_t* data, | |
5733 intptr_t len, | |
5734 Heap::Space space = Heap::kNew); | |
5735 | |
5736 private: | |
5737 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
5738 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
5739 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
5740 } | |
5741 | |
5742 FINAL_HEAP_OBJECT_IMPLEMENTATION(Uint64Array, ByteArray); | |
5743 friend class ByteArray; | |
5744 friend class Class; | |
5745 }; | |
5746 | |
5747 | |
5748 class Float32Array : public ByteArray { | |
5749 public: | |
5750 intptr_t ByteLength() const { | |
5751 return Length() * kBytesPerElement; | |
5752 } | |
5753 | |
5754 float At(intptr_t index) const { | |
5755 ASSERT((index >= 0) && (index < Length())); | |
5756 return raw_ptr()->data_[index]; | |
5757 } | |
5758 | |
5759 void SetAt(intptr_t index, float value) const { | |
5760 ASSERT((index >= 0) && (index < Length())); | |
5761 raw_ptr()->data_[index] = value; | |
5762 } | |
5763 | |
5764 static const intptr_t kBytesPerElement = 4; | |
5765 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | |
5766 | |
5767 static intptr_t data_offset() { | |
5768 return OFFSET_OF(RawFloat32Array, data_); | |
5769 } | |
5770 | |
5771 static intptr_t InstanceSize() { | |
5772 ASSERT(sizeof(RawFloat32Array) == OFFSET_OF(RawFloat32Array, data_)); | |
5773 return 0; | |
5774 } | |
5775 | |
5776 static intptr_t InstanceSize(intptr_t len) { | |
5777 ASSERT(0 <= len && len <= kMaxElements); | |
5778 return RoundedAllocationSize( | |
5779 sizeof(RawFloat32Array) + (len * kBytesPerElement)); | |
5780 } | |
5781 | |
5782 static RawFloat32Array* New(intptr_t len, | |
5783 Heap::Space space = Heap::kNew); | |
5784 static RawFloat32Array* New(const float* data, | |
5785 intptr_t len, | |
5786 Heap::Space space = Heap::kNew); | |
5787 | |
5788 private: | |
5789 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
5790 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
5791 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
5792 } | |
5793 | |
5794 FINAL_HEAP_OBJECT_IMPLEMENTATION(Float32Array, ByteArray); | |
5795 friend class ByteArray; | |
5796 friend class Class; | |
5797 }; | |
5798 | |
5799 | |
5800 class Float64Array : public ByteArray { | |
5801 public: | |
5802 intptr_t ByteLength() const { | |
5803 return Length() * kBytesPerElement; | |
5804 } | |
5805 | |
5806 double At(intptr_t index) const { | |
5807 ASSERT((index >= 0) && (index < Length())); | |
5808 return raw_ptr()->data_[index]; | |
5809 } | |
5810 | |
5811 void SetAt(intptr_t index, double value) const { | |
5812 ASSERT((index >= 0) && (index < Length())); | |
5813 raw_ptr()->data_[index] = value; | |
5814 } | |
5815 | |
5816 static const intptr_t kBytesPerElement = 8; | |
5817 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; | |
5818 | |
5819 static intptr_t InstanceSize() { | |
5820 ASSERT(sizeof(RawFloat64Array) == OFFSET_OF(RawFloat64Array, data_)); | |
5821 return 0; | |
5822 } | |
5823 | |
5824 static intptr_t data_offset() { | |
5825 return OFFSET_OF(RawFloat64Array, data_); | |
5826 } | |
5827 | |
5828 static intptr_t InstanceSize(intptr_t len) { | |
5829 ASSERT(0 <= len && len <= kMaxElements); | |
5830 return RoundedAllocationSize( | |
5831 sizeof(RawFloat64Array) + (len * kBytesPerElement)); | |
5832 } | |
5833 | |
5834 static RawFloat64Array* New(intptr_t len, | |
5835 Heap::Space space = Heap::kNew); | |
5836 static RawFloat64Array* New(const double* data, | |
5837 intptr_t len, | |
5838 Heap::Space space = Heap::kNew); | |
5839 | |
5840 private: | |
5841 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
5842 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
5843 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; | |
5844 } | |
5845 | |
5846 FINAL_HEAP_OBJECT_IMPLEMENTATION(Float64Array, ByteArray); | |
5847 friend class ByteArray; | |
5848 friend class Class; | |
5849 }; | |
5850 | |
5851 | |
5852 class ExternalInt8Array : public ByteArray { | |
5853 public: | |
5854 intptr_t ByteLength() const { | |
5855 return Length() * kBytesPerElement; | |
5856 } | |
5857 | |
5858 int8_t At(intptr_t index) const { | |
5859 ASSERT((index >= 0) && (index < Length())); | |
5860 return raw_ptr()->data_[index]; | |
5861 } | |
5862 | |
5863 void SetAt(intptr_t index, int8_t value) const { | |
5864 ASSERT((index >= 0) && (index < Length())); | |
5865 raw_ptr()->data_[index] = value; | |
5866 } | |
5867 | |
5868 int8_t* GetData() const { | |
5869 return raw_ptr()->data_; | |
5870 } | |
5871 | |
5872 void* GetPeer() const { | |
5873 return raw_ptr()->peer_; | |
5874 } | |
5875 | |
5876 static const intptr_t kBytesPerElement = 1; | |
5877 | |
5878 // Since external arrays may be serialized to non-external ones, | |
5879 // enforce the same maximum element count. | |
5880 static const intptr_t kMaxElements = Int8Array::kMaxElements; | |
5881 | |
5882 static intptr_t InstanceSize() { | |
5883 return RoundedAllocationSize(sizeof(RawExternalInt8Array)); | |
5884 } | |
5885 | |
5886 static intptr_t data_offset() { | |
5887 return OFFSET_OF(RawExternalInt8Array, data_); | |
5888 } | |
5889 | |
5890 static RawExternalInt8Array* New(int8_t* data, | |
5891 intptr_t len, | |
5892 Heap::Space space = Heap::kNew); | |
5893 | |
5894 private: | |
5895 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
5896 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
5897 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); | |
5898 return data + byte_offset; | |
5899 } | |
5900 | |
5901 void SetData(int8_t* data) const { | |
5902 raw_ptr()->data_ = data; | |
5903 } | |
5904 | |
5905 void SetPeer(void* peer) const { | |
5906 raw_ptr()->peer_ = peer; | |
5907 } | |
5908 | |
5909 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalInt8Array, ByteArray); | |
5910 friend class ByteArray; | |
5911 friend class Class; | |
5912 }; | |
5913 | |
5914 | |
5915 class ExternalUint8Array : public ByteArray { | |
5916 public: | |
5917 intptr_t ByteLength() const { | |
5918 return Length() * kBytesPerElement; | |
5919 } | |
5920 | |
5921 uint8_t At(intptr_t index) const { | |
5922 ASSERT((index >= 0) && (index < Length())); | |
5923 return raw_ptr()->data_[index]; | |
5924 } | |
5925 | |
5926 void SetAt(intptr_t index, uint8_t value) const { | |
5927 ASSERT((index >= 0) && (index < Length())); | |
5928 raw_ptr()->data_[index] = value; | |
5929 } | |
5930 | |
5931 uint8_t* GetData() const { | |
5932 return raw_ptr()->data_; | |
5933 } | |
5934 | |
5935 void* GetPeer() const { | |
5936 return raw_ptr()->peer_; | |
5937 } | |
5938 | |
5939 static const intptr_t kBytesPerElement = 1; | |
5940 | |
5941 // Since external arrays may be serialized to non-external ones, | |
5942 // enforce the same maximum element count. | |
5943 static const intptr_t kMaxElements = Uint8Array::kMaxElements; | |
5944 | |
5945 static intptr_t InstanceSize() { | |
5946 return RoundedAllocationSize(sizeof(RawExternalUint8Array)); | |
5947 } | |
5948 | |
5949 static intptr_t data_offset() { | |
5950 return OFFSET_OF(RawExternalUint8Array, data_); | |
5951 } | |
5952 | |
5953 static RawExternalUint8Array* New(uint8_t* data, | |
5954 intptr_t len, | |
5955 Heap::Space space = Heap::kNew); | |
5956 | |
5957 private: | |
5958 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
5959 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
5960 uint8_t* data = | |
5961 reinterpret_cast<uint8_t*>(raw_ptr()->data_); | |
5962 return data + byte_offset; | |
5963 } | |
5964 | |
5965 void SetData(uint8_t* data) const { | |
5966 raw_ptr()->data_ = data; | |
5967 } | |
5968 | |
5969 void SetPeer(void* peer) const { | |
5970 raw_ptr()->peer_ = peer; | |
5971 } | |
5972 | |
5973 HEAP_OBJECT_IMPLEMENTATION(ExternalUint8Array, ByteArray); | |
5974 friend class ByteArray; | |
5975 friend class Class; | |
5976 friend class TokenStream; | |
5977 }; | |
5978 | |
5979 | |
5980 class ExternalUint8ClampedArray : public ExternalUint8Array { | |
5981 public: | |
5982 static RawExternalUint8ClampedArray* New(uint8_t* data, | |
5983 intptr_t len, | |
5984 Heap::Space space = Heap::kNew); | |
5985 | |
5986 private: | |
5987 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint8ClampedArray, | |
5988 ExternalUint8Array); | |
5989 friend class Class; | |
5990 }; | |
5991 | |
5992 | |
5993 class ExternalInt16Array : public ByteArray { | |
5994 public: | |
5995 intptr_t ByteLength() const { | |
5996 return Length() * kBytesPerElement; | |
5997 } | |
5998 | |
5999 int16_t At(intptr_t index) const { | |
6000 ASSERT((index >= 0) && (index < Length())); | |
6001 return raw_ptr()->data_[index]; | |
6002 } | |
6003 | |
6004 void SetAt(intptr_t index, int16_t value) const { | |
6005 ASSERT((index >= 0) && (index < Length())); | |
6006 raw_ptr()->data_[index] = value; | |
6007 } | |
6008 | |
6009 int16_t* GetData() const { | |
6010 return raw_ptr()->data_; | |
6011 } | |
6012 | |
6013 void* GetPeer() const { | |
6014 return raw_ptr()->peer_; | |
6015 } | |
6016 | |
6017 static const intptr_t kBytesPerElement = 2; | |
6018 | |
6019 // Since external arrays may be serialized to non-external ones, | |
6020 // enforce the same maximum element count. | |
6021 static const intptr_t kMaxElements = Int16Array::kMaxElements; | |
6022 | |
6023 static intptr_t InstanceSize() { | |
6024 return RoundedAllocationSize(sizeof(RawExternalInt16Array)); | |
6025 } | |
6026 | |
6027 static RawExternalInt16Array* New(int16_t* data, | |
6028 intptr_t len, | |
6029 Heap::Space space = Heap::kNew); | |
6030 | |
6031 private: | |
6032 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
6033 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
6034 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); | |
6035 return data + byte_offset; | |
6036 } | |
6037 | |
6038 void SetData(int16_t* data) const { | |
6039 raw_ptr()->data_ = data; | |
6040 } | |
6041 | |
6042 void SetPeer(void* peer) const { | |
6043 raw_ptr()->peer_ = peer; | |
6044 } | |
6045 | |
6046 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalInt16Array, ByteArray); | |
6047 friend class ByteArray; | |
6048 friend class Class; | |
6049 }; | |
6050 | |
6051 | |
6052 class ExternalUint16Array : public ByteArray { | |
6053 public: | |
6054 intptr_t ByteLength() const { | |
6055 return Length() * kBytesPerElement; | |
6056 } | |
6057 | |
6058 int16_t At(intptr_t index) const { | |
6059 ASSERT((index >= 0) && (index < Length())); | |
6060 return raw_ptr()->data_[index]; | |
6061 } | |
6062 | |
6063 void SetAt(intptr_t index, int16_t value) const { | |
6064 ASSERT((index >= 0) && (index < Length())); | |
6065 raw_ptr()->data_[index] = value; | |
6066 } | |
6067 | |
6068 uint16_t* GetData() const { | |
6069 return raw_ptr()->data_; | |
6070 } | |
6071 | |
6072 void* GetPeer() const { | |
6073 return raw_ptr()->peer_; | |
6074 } | |
6075 | |
6076 static const intptr_t kBytesPerElement = 2; | |
6077 | |
6078 // Since external arrays may be serialized to non-external ones, | |
6079 // enforce the same maximum element count. | |
6080 static const intptr_t kMaxElements = Uint16Array::kMaxElements; | |
6081 | |
6082 static intptr_t InstanceSize() { | |
6083 return RoundedAllocationSize(sizeof(RawExternalUint16Array)); | |
6084 } | |
6085 | |
6086 static RawExternalUint16Array* New(uint16_t* data, | |
6087 intptr_t len, | |
6088 Heap::Space space = Heap::kNew); | |
6089 | |
6090 private: | |
6091 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
6092 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
6093 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); | |
6094 return data + byte_offset; | |
6095 } | |
6096 | |
6097 void SetData(uint16_t* data) const { | |
6098 raw_ptr()->data_ = data; | |
6099 } | |
6100 | |
6101 void SetPeer(void* peer) const { | |
6102 raw_ptr()->peer_ = peer; | |
6103 } | |
6104 | |
6105 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint16Array, ByteArray); | |
6106 friend class ByteArray; | |
6107 friend class Class; | |
6108 }; | |
6109 | |
6110 | |
6111 class ExternalInt32Array : public ByteArray { | |
6112 public: | |
6113 intptr_t ByteLength() const { | |
6114 return Length() * kBytesPerElement; | |
6115 } | |
6116 | |
6117 int32_t At(intptr_t index) const { | |
6118 ASSERT((index >= 0) && (index < Length())); | |
6119 return raw_ptr()->data_[index]; | |
6120 } | |
6121 | |
6122 void SetAt(intptr_t index, int32_t value) const { | |
6123 ASSERT((index >= 0) && (index < Length())); | |
6124 raw_ptr()->data_[index] = value; | |
6125 } | |
6126 | |
6127 int32_t* GetData() const { | |
6128 return raw_ptr()->data_; | |
6129 } | |
6130 | |
6131 void* GetPeer() const { | |
6132 return raw_ptr()->peer_; | |
6133 } | |
6134 | |
6135 static const intptr_t kBytesPerElement = 4; | |
6136 | |
6137 // Since external arrays may be serialized to non-external ones, | |
6138 // enforce the same maximum element count. | |
6139 static const intptr_t kMaxElements = Int32Array::kMaxElements; | |
6140 | |
6141 static intptr_t InstanceSize() { | |
6142 return RoundedAllocationSize(sizeof(RawExternalInt32Array)); | |
6143 } | |
6144 | |
6145 static RawExternalInt32Array* New(int32_t* data, | |
6146 intptr_t len, | |
6147 Heap::Space space = Heap::kNew); | |
6148 | |
6149 private: | |
6150 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
6151 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
6152 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); | |
6153 return data + byte_offset; | |
6154 } | |
6155 | |
6156 void SetData(int32_t* data) const { | |
6157 raw_ptr()->data_ = data; | |
6158 } | |
6159 | |
6160 void SetPeer(void* peer) const { | |
6161 raw_ptr()->peer_ = peer; | |
6162 } | |
6163 | |
6164 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalInt32Array, ByteArray); | |
6165 friend class ByteArray; | |
6166 friend class Class; | |
6167 }; | |
6168 | |
6169 | |
6170 class ExternalUint32Array : public ByteArray { | |
6171 public: | |
6172 intptr_t ByteLength() const { | |
6173 return Length() * kBytesPerElement; | |
6174 } | |
6175 | |
6176 int32_t At(intptr_t index) const { | |
6177 ASSERT((index >= 0) && (index < Length())); | |
6178 return raw_ptr()->data_[index]; | |
6179 } | |
6180 | |
6181 void SetAt(intptr_t index, int32_t value) const { | |
6182 ASSERT((index >= 0) && (index < Length())); | |
6183 raw_ptr()->data_[index] = value; | |
6184 } | |
6185 | |
6186 uint32_t* GetData() const { | |
6187 return raw_ptr()->data_; | |
6188 } | |
6189 | |
6190 void* GetPeer() const { | |
6191 return raw_ptr()->peer_; | |
6192 } | |
6193 | |
6194 static const intptr_t kBytesPerElement = 4; | |
6195 | |
6196 // Since external arrays may be serialized to non-external ones, | |
6197 // enforce the same maximum element count. | |
6198 static const intptr_t kMaxElements = Uint32Array::kMaxElements; | |
6199 | |
6200 static intptr_t InstanceSize() { | |
6201 return RoundedAllocationSize(sizeof(RawExternalUint32Array)); | |
6202 } | |
6203 | |
6204 static RawExternalUint32Array* New(uint32_t* data, | |
6205 intptr_t len, | |
6206 Heap::Space space = Heap::kNew); | |
6207 | |
6208 private: | |
6209 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
6210 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
6211 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); | |
6212 return data + byte_offset; | |
6213 } | |
6214 | |
6215 void SetData(uint32_t* data) const { | |
6216 raw_ptr()->data_ = data; | |
6217 } | |
6218 | |
6219 void SetPeer(void* peer) const { | |
6220 raw_ptr()->peer_ = peer; | |
6221 } | |
6222 | |
6223 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint32Array, ByteArray); | |
6224 friend class ByteArray; | |
6225 friend class Class; | |
6226 }; | |
6227 | |
6228 | |
6229 class ExternalInt64Array : public ByteArray { | |
6230 public: | |
6231 intptr_t ByteLength() const { | |
6232 return Length() * kBytesPerElement; | |
6233 } | |
6234 | |
6235 int64_t At(intptr_t index) const { | |
6236 ASSERT((index >= 0) && (index < Length())); | |
6237 return raw_ptr()->data_[index]; | |
6238 } | |
6239 | |
6240 void SetAt(intptr_t index, int64_t value) const { | |
6241 ASSERT((index >= 0) && (index < Length())); | |
6242 raw_ptr()->data_[index] = value; | |
6243 } | |
6244 | |
6245 int64_t* GetData() const { | |
6246 return raw_ptr()->data_; | |
6247 } | |
6248 | |
6249 void* GetPeer() const { | |
6250 return raw_ptr()->peer_; | |
6251 } | |
6252 | |
6253 static const intptr_t kBytesPerElement = 8; | |
6254 | |
6255 // Since external arrays may be serialized to non-external ones, | |
6256 // enforce the same maximum element count. | |
6257 static const intptr_t kMaxElements = Int64Array::kMaxElements; | |
6258 | |
6259 static intptr_t InstanceSize() { | |
6260 return RoundedAllocationSize(sizeof(RawExternalInt64Array)); | |
6261 } | |
6262 | |
6263 static RawExternalInt64Array* New(int64_t* data, | |
6264 intptr_t len, | |
6265 Heap::Space space = Heap::kNew); | |
6266 | |
6267 private: | |
6268 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
6269 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
6270 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); | |
6271 return data + byte_offset; | |
6272 } | |
6273 | |
6274 void SetData(int64_t* data) const { | |
6275 raw_ptr()->data_ = data; | |
6276 } | |
6277 | |
6278 void SetPeer(void* peer) const { | |
6279 raw_ptr()->peer_ = peer; | |
6280 } | |
6281 | |
6282 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalInt64Array, ByteArray); | |
6283 friend class ByteArray; | |
6284 friend class Class; | |
6285 }; | |
6286 | |
6287 | |
6288 class ExternalUint64Array : public ByteArray { | |
6289 public: | |
6290 intptr_t ByteLength() const { | |
6291 return Length() * kBytesPerElement; | |
6292 } | |
6293 | |
6294 int64_t At(intptr_t index) const { | |
6295 ASSERT((index >= 0) && (index < Length())); | |
6296 return raw_ptr()->data_[index]; | |
6297 } | |
6298 | |
6299 void SetAt(intptr_t index, int64_t value) const { | |
6300 ASSERT((index >= 0) && (index < Length())); | |
6301 raw_ptr()->data_[index] = value; | |
6302 } | |
6303 | |
6304 uint64_t* GetData() const { | |
6305 return raw_ptr()->data_; | |
6306 } | |
6307 | |
6308 void* GetPeer() const { | |
6309 return raw_ptr()->peer_; | |
6310 } | |
6311 | |
6312 static const intptr_t kBytesPerElement = 8; | |
6313 | |
6314 // Since external arrays may be serialized to non-external ones, | |
6315 // enforce the same maximum element count. | |
6316 static const intptr_t kMaxElements = Uint64Array::kMaxElements; | |
6317 | |
6318 static intptr_t InstanceSize() { | |
6319 return RoundedAllocationSize(sizeof(RawExternalUint64Array)); | |
6320 } | |
6321 | |
6322 static RawExternalUint64Array* New(uint64_t* data, | |
6323 intptr_t len, | |
6324 Heap::Space space = Heap::kNew); | |
6325 | |
6326 private: | |
6327 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
6328 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
6329 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); | |
6330 return data + byte_offset; | |
6331 } | |
6332 | |
6333 void SetData(uint64_t* data) const { | |
6334 raw_ptr()->data_ = data; | |
6335 } | |
6336 | |
6337 void SetPeer(void* peer) const { | |
6338 raw_ptr()->peer_ = peer; | |
6339 } | |
6340 | |
6341 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalUint64Array, ByteArray); | |
6342 friend class ByteArray; | |
6343 friend class Class; | |
6344 }; | |
6345 | |
6346 | |
6347 class ExternalFloat32Array : public ByteArray { | |
6348 public: | |
6349 intptr_t ByteLength() const { | |
6350 return Length() * kBytesPerElement; | |
6351 } | |
6352 | |
6353 float At(intptr_t index) const { | |
6354 ASSERT((index >= 0) && (index < Length())); | |
6355 return raw_ptr()->data_[index]; | |
6356 } | |
6357 | |
6358 void SetAt(intptr_t index, float value) const { | |
6359 ASSERT((index >= 0) && (index < Length())); | |
6360 raw_ptr()->data_[index] = value; | |
6361 } | |
6362 | |
6363 float* GetData() const { | |
6364 return raw_ptr()->data_; | |
6365 } | |
6366 | |
6367 void* GetPeer() const { | |
6368 return raw_ptr()->peer_; | |
6369 } | |
6370 | |
6371 static const intptr_t kBytesPerElement = 4; | |
6372 | |
6373 // Since external arrays may be serialized to non-external ones, | |
6374 // enforce the same maximum element count. | |
6375 static const intptr_t kMaxElements = Float32Array::kMaxElements; | |
6376 | |
6377 static intptr_t InstanceSize() { | |
6378 return RoundedAllocationSize(sizeof(RawExternalFloat32Array)); | |
6379 } | |
6380 | |
6381 static RawExternalFloat32Array* New(float* data, | |
6382 intptr_t len, | |
6383 Heap::Space space = Heap::kNew); | |
6384 | |
6385 private: | |
6386 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
6387 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
6388 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); | |
6389 return data + byte_offset; | |
6390 } | |
6391 | |
6392 void SetData(float* data) const { | |
6393 raw_ptr()->data_ = data; | |
6394 } | |
6395 | |
6396 void SetPeer(void* peer) const { | |
6397 raw_ptr()->peer_ = peer; | |
6398 } | |
6399 | |
6400 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalFloat32Array, ByteArray); | |
6401 friend class ByteArray; | |
6402 friend class Class; | |
6403 }; | |
6404 | |
6405 | |
6406 class ExternalFloat64Array : public ByteArray { | |
6407 public: | |
6408 intptr_t ByteLength() const { | |
6409 return Length() * kBytesPerElement; | |
6410 } | |
6411 | |
6412 double At(intptr_t index) const { | |
6413 ASSERT((index >= 0) && (index < Length())); | |
6414 return raw_ptr()->data_[index]; | |
6415 } | |
6416 | |
6417 void SetAt(intptr_t index, double value) const { | |
6418 ASSERT((index >= 0) && (index < Length())); | |
6419 raw_ptr()->data_[index] = value; | |
6420 } | |
6421 | |
6422 double* GetData() const { | |
6423 return raw_ptr()->data_; | |
6424 } | |
6425 | |
6426 void* GetPeer() const { | |
6427 return raw_ptr()->peer_; | |
6428 } | |
6429 | |
6430 static const intptr_t kBytesPerElement = 8; | |
6431 | |
6432 // Since external arrays may be serialized to non-external ones, | |
6433 // enforce the same maximum element count. | |
6434 static const intptr_t kMaxElements = Float64Array::kMaxElements; | |
6435 | |
6436 static intptr_t InstanceSize() { | |
6437 return RoundedAllocationSize(sizeof(RawExternalFloat64Array)); | |
6438 } | |
6439 | |
6440 static RawExternalFloat64Array* New(double* data, | |
6441 intptr_t len, | |
6442 Heap::Space space = Heap::kNew); | |
6443 | |
6444 private: | |
6445 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
6446 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); | |
6447 uint8_t* data = reinterpret_cast<uint8_t*>(raw_ptr()->data_); | |
6448 return data + byte_offset; | |
6449 } | |
6450 | |
6451 void SetData(double* data) const { | |
6452 raw_ptr()->data_ = data; | |
6453 } | |
6454 | |
6455 void SetPeer(void* peer) const { | |
6456 raw_ptr()->peer_ = peer; | |
6457 } | |
6458 | |
6459 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalFloat64Array, ByteArray); | |
6460 friend class ByteArray; | |
6461 friend class Class; | |
6462 }; | |
6463 | |
6464 | |
6465 // DartFunction represents the abstract Dart class 'Function'. | 5207 // DartFunction represents the abstract Dart class 'Function'. |
6466 class DartFunction : public Instance { | 5208 class DartFunction : public Instance { |
6467 private: | 5209 private: |
6468 FINAL_HEAP_OBJECT_IMPLEMENTATION(DartFunction, Instance); | 5210 FINAL_HEAP_OBJECT_IMPLEMENTATION(DartFunction, Instance); |
6469 friend class Class; | 5211 friend class Class; |
6470 friend class Instance; | 5212 friend class Instance; |
6471 }; | 5213 }; |
6472 | 5214 |
6473 | 5215 |
6474 class Closure : public AllStatic { | 5216 class Closure : public AllStatic { |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6762 | 5504 |
6763 | 5505 |
6764 void Context::SetAt(intptr_t index, const Instance& value) const { | 5506 void Context::SetAt(intptr_t index, const Instance& value) const { |
6765 StorePointer(InstanceAddr(index), value.raw()); | 5507 StorePointer(InstanceAddr(index), value.raw()); |
6766 } | 5508 } |
6767 | 5509 |
6768 | 5510 |
6769 intptr_t Instance::GetNativeField(Isolate* isolate, int index) const { | 5511 intptr_t Instance::GetNativeField(Isolate* isolate, int index) const { |
6770 ASSERT(IsValidNativeIndex(index)); | 5512 ASSERT(IsValidNativeIndex(index)); |
6771 NoGCScope no_gc; | 5513 NoGCScope no_gc; |
6772 RawIntPtrArray* native_fields = | 5514 RawTypedData* native_fields = |
6773 reinterpret_cast<RawIntPtrArray*>(*NativeFieldsAddr()); | 5515 reinterpret_cast<RawTypedData*>(*NativeFieldsAddr()); |
6774 if (native_fields == IntPtrArray::null()) { | 5516 if (native_fields == TypedData::null()) { |
6775 return 0; | 5517 return 0; |
6776 } | 5518 } |
6777 return native_fields->ptr()->data_[index]; | 5519 intptr_t byte_offset = index * sizeof(intptr_t); |
| 5520 return *reinterpret_cast<intptr_t*>(native_fields->ptr()->data_ + |
| 5521 byte_offset); |
6778 } | 5522 } |
6779 | 5523 |
6780 | 5524 |
6781 bool String::Equals(const String& str) const { | 5525 bool String::Equals(const String& str) const { |
6782 if (raw() == str.raw()) { | 5526 if (raw() == str.raw()) { |
6783 return true; // Both handles point to the same raw instance. | 5527 return true; // Both handles point to the same raw instance. |
6784 } | 5528 } |
6785 if (str.IsNull()) { | 5529 if (str.IsNull()) { |
6786 return false; | 5530 return false; |
6787 } | 5531 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6823 | 5567 |
6824 | 5568 |
6825 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, | 5569 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, |
6826 intptr_t index) { | 5570 intptr_t index) { |
6827 return array.At((index * kEntryLength) + kTargetFunctionIndex); | 5571 return array.At((index * kEntryLength) + kTargetFunctionIndex); |
6828 } | 5572 } |
6829 | 5573 |
6830 } // namespace dart | 5574 } // namespace dart |
6831 | 5575 |
6832 #endif // VM_OBJECT_H_ | 5576 #endif // VM_OBJECT_H_ |
OLD | NEW |