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

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

Issue 13472019: - Create an all static TypedDataView class which uses implicit field offset (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 3414 matching lines...) Expand 10 before | Expand all | Expand 10 after
3425 } 3425 }
3426 void SetFieldAtOffset(intptr_t offset, const Object& value) const { 3426 void SetFieldAtOffset(intptr_t offset, const Object& value) const {
3427 StorePointer(FieldAddrAtOffset(offset), value.raw()); 3427 StorePointer(FieldAddrAtOffset(offset), value.raw());
3428 } 3428 }
3429 bool IsValidFieldOffset(int offset) const; 3429 bool IsValidFieldOffset(int offset) const;
3430 3430
3431 // TODO(iposva): Determine if this gets in the way of Smi. 3431 // TODO(iposva): Determine if this gets in the way of Smi.
3432 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); 3432 HEAP_OBJECT_IMPLEMENTATION(Instance, Object);
3433 friend class Class; 3433 friend class Class;
3434 friend class Closure; 3434 friend class Closure;
3435 friend class TypedDataView;
3435 }; 3436 };
3436 3437
3437 3438
3438 // AbstractType is an abstract superclass. 3439 // AbstractType is an abstract superclass.
3439 // Subclasses of AbstractType are Type and TypeParameter. 3440 // Subclasses of AbstractType are Type and TypeParameter.
3440 class AbstractType : public Instance { 3441 class AbstractType : public Instance {
3441 public: 3442 public:
3442 virtual bool IsFinalized() const; 3443 virtual bool IsFinalized() const;
3443 virtual bool IsBeingFinalized() const; 3444 virtual bool IsBeingFinalized() const;
3444 virtual bool IsMalformed() const; 3445 virtual bool IsMalformed() const;
(...skipping 1638 matching lines...) Expand 10 before | Expand all | Expand 10 after
5083 static RawTypedData* New(intptr_t class_id, 5084 static RawTypedData* New(intptr_t class_id,
5084 intptr_t len, 5085 intptr_t len,
5085 Heap::Space space = Heap::kNew); 5086 Heap::Space space = Heap::kNew);
5086 5087
5087 static void Copy(const TypedData& dst, 5088 static void Copy(const TypedData& dst,
5088 intptr_t dst_offset_in_bytes, 5089 intptr_t dst_offset_in_bytes,
5089 const TypedData& src, 5090 const TypedData& src,
5090 intptr_t src_offset_in_bytes, 5091 intptr_t src_offset_in_bytes,
5091 intptr_t length_in_bytes); 5092 intptr_t length_in_bytes);
5092 5093
5094 static bool IsTypedData(const Instance& obj) {
5095 ASSERT(!obj.IsNull());
5096 intptr_t cid = obj.raw()->GetClassId();
5097 return RawObject::IsTypedDataClassId(cid);
5098 }
5099
5093 protected: 5100 protected:
5094 void SetLength(intptr_t value) const { 5101 void SetLength(intptr_t value) const {
5095 raw_ptr()->length_ = Smi::New(value); 5102 raw_ptr()->length_ = Smi::New(value);
5096 } 5103 }
5097 5104
5098 private: 5105 private:
5099 static const intptr_t element_size[]; 5106 static const intptr_t element_size[];
5100 5107
5101 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypedData, Instance); 5108 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypedData, Instance);
5102 friend class Class; 5109 friend class Class;
5103 friend class ExternalTypedData; 5110 friend class ExternalTypedData;
5111 friend class TypedDataView;
5104 }; 5112 };
5105 5113
5106 5114
5107 class ExternalTypedData : public Instance { 5115 class ExternalTypedData : public Instance {
5108 public: 5116 public:
5109 intptr_t Length() const { 5117 intptr_t Length() const {
5110 ASSERT(!IsNull()); 5118 ASSERT(!IsNull());
5111 return Smi::Value(raw_ptr()->length_); 5119 return Smi::Value(raw_ptr()->length_);
5112 } 5120 }
5113 5121
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
5178 uint8_t* data, 5186 uint8_t* data,
5179 intptr_t len, 5187 intptr_t len,
5180 Heap::Space space = Heap::kNew); 5188 Heap::Space space = Heap::kNew);
5181 5189
5182 static void Copy(const ExternalTypedData& dst, 5190 static void Copy(const ExternalTypedData& dst,
5183 intptr_t dst_offset_in_bytes, 5191 intptr_t dst_offset_in_bytes,
5184 const ExternalTypedData& src, 5192 const ExternalTypedData& src,
5185 intptr_t src_offset_in_bytes, 5193 intptr_t src_offset_in_bytes,
5186 intptr_t length_in_bytes); 5194 intptr_t length_in_bytes);
5187 5195
5196 static bool IsExternalTypedData(const Instance& obj) {
5197 ASSERT(!obj.IsNull());
5198 intptr_t cid = obj.raw()->GetClassId();
5199 return RawObject::IsExternalTypedDataClassId(cid);
5200 }
5201
5188 protected: 5202 protected:
5189 void SetLength(intptr_t value) const { 5203 void SetLength(intptr_t value) const {
5190 raw_ptr()->length_ = Smi::New(value); 5204 raw_ptr()->length_ = Smi::New(value);
5191 } 5205 }
5192 5206
5193 void SetData(uint8_t* data) const { 5207 void SetData(uint8_t* data) const {
5194 raw_ptr()->data_ = data; 5208 raw_ptr()->data_ = data;
5195 } 5209 }
5196 5210
5197 void SetPeer(void* peer) const { 5211 void SetPeer(void* peer) const {
5198 raw_ptr()->peer_ = peer; 5212 raw_ptr()->peer_ = peer;
5199 } 5213 }
5200 5214
5201 private: 5215 private:
5202 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData, Instance); 5216 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData, Instance);
5203 friend class Class; 5217 friend class Class;
5204 }; 5218 };
5205 5219
5206 5220
5221 class TypedDataView : public AllStatic {
5222 public:
5223 static intptr_t ElementSizeInBytes(const Instance& view_obj) {
5224 ASSERT(!view_obj.IsNull());
5225 intptr_t cid = view_obj.raw()->GetClassId();
5226 return ElementSizeInBytes(cid);
5227 }
5228
5229 static RawInstance* Data(const Instance& view_obj) {
5230 ASSERT(!view_obj.IsNull());
5231 return *reinterpret_cast<RawInstance**>(view_obj.raw_ptr() + kDataOffset);
5232 }
5233
5234 static RawSmi* OffsetInBytes(const Instance& view_obj) {
5235 ASSERT(!view_obj.IsNull());
5236 return *reinterpret_cast<RawSmi**>(
5237 view_obj.raw_ptr() + kOffsetInBytesOffset);
5238 }
5239
5240 static RawSmi* Length(const Instance& view_obj) {
5241 ASSERT(!view_obj.IsNull());
5242 return *reinterpret_cast<RawSmi**>(view_obj.raw_ptr() + kLengthOffset);
5243 }
5244
5245 static bool IsExternalTypedDataView(const Instance& view_obj) {
5246 const Instance& data = Instance::Handle(Data(view_obj));
5247 intptr_t cid = data.raw()->GetClassId();
5248 ASSERT(RawObject::IsTypedDataClassId(cid) ||
5249 RawObject::IsExternalTypedDataClassId(cid));
5250 return RawObject::IsExternalTypedDataClassId(cid);
5251 }
5252
5253 static intptr_t NumberOfFields() {
5254 return (kLengthOffset - kTypeArguments);
5255 }
5256
5257 static intptr_t data_offset() {
5258 return kWordSize * kDataOffset;
5259 }
5260
5261 static intptr_t offset_in_bytes_offset() {
5262 return kWordSize * kOffsetInBytesOffset;
5263 }
5264
5265 static intptr_t length_offset() {
5266 return kWordSize * kLengthOffset;
5267 }
5268
5269 static intptr_t ElementSizeInBytes(intptr_t class_id) {
5270 ASSERT(RawObject::IsTypedDataViewClassId(class_id));
5271 return (class_id == kByteDataViewCid) ?
5272 TypedData::element_size[kTypedDataInt8ArrayCid] :
5273 TypedData::element_size[class_id - kTypedDataInt8ArrayViewCid];
5274 }
5275
5276 private:
5277 enum {
5278 kTypeArguments = 1,
5279 kDataOffset = 2,
5280 kOffsetInBytesOffset = 3,
5281 kLengthOffset = 4,
5282 };
5283 };
5284
5285
5207 // DartFunction represents the abstract Dart class 'Function'. 5286 // DartFunction represents the abstract Dart class 'Function'.
5208 class DartFunction : public Instance { 5287 class DartFunction : public Instance {
5209 private: 5288 private:
5210 FINAL_HEAP_OBJECT_IMPLEMENTATION(DartFunction, Instance); 5289 FINAL_HEAP_OBJECT_IMPLEMENTATION(DartFunction, Instance);
5211 friend class Class; 5290 friend class Class;
5212 friend class Instance; 5291 friend class Instance;
5213 }; 5292 };
5214 5293
5215 5294
5216 class Closure : public AllStatic { 5295 class Closure : public AllStatic {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
5567 5646
5568 5647
5569 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 5648 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
5570 intptr_t index) { 5649 intptr_t index) {
5571 return array.At((index * kEntryLength) + kTargetFunctionIndex); 5650 return array.At((index * kEntryLength) + kTargetFunctionIndex);
5572 } 5651 }
5573 5652
5574 } // namespace dart 5653 } // namespace dart
5575 5654
5576 #endif // VM_OBJECT_H_ 5655 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698