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

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

Issue 14296006: Fast copy between TypedData and ExternalTypedData (Closed) Base URL: https://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
« no previous file with comments | « runtime/lib/typeddata.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5016 matching lines...) Expand 10 before | Expand all | Expand 10 after
5027 intptr_t Length() const { 5027 intptr_t Length() const {
5028 ASSERT(!IsNull()); 5028 ASSERT(!IsNull());
5029 return Smi::Value(raw_ptr()->length_); 5029 return Smi::Value(raw_ptr()->length_);
5030 } 5030 }
5031 5031
5032 intptr_t ElementSizeInBytes() const { 5032 intptr_t ElementSizeInBytes() const {
5033 intptr_t cid = raw()->GetClassId(); 5033 intptr_t cid = raw()->GetClassId();
5034 return ElementSizeInBytes(cid); 5034 return ElementSizeInBytes(cid);
5035 } 5035 }
5036 5036
5037
5038 TypeDataElementType ElementType() const {
5039 intptr_t cid = raw()->GetClassId();
5040 return ElementType(cid);
5041 }
5042
5037 intptr_t LengthInBytes() const { 5043 intptr_t LengthInBytes() const {
5038 intptr_t cid = raw()->GetClassId(); 5044 intptr_t cid = raw()->GetClassId();
5039 return (ElementSizeInBytes(cid) * Length()); 5045 return (ElementSizeInBytes(cid) * Length());
5040 } 5046 }
5041 5047
5042 void* DataAddr(intptr_t byte_offset) const { 5048 void* DataAddr(intptr_t byte_offset) const {
5043 ASSERT((byte_offset >= 0) && (byte_offset < LengthInBytes())); 5049 ASSERT((byte_offset >= 0) && (byte_offset < LengthInBytes()));
5044 return reinterpret_cast<void*>(raw_ptr()->data_ + byte_offset); 5050 return reinterpret_cast<void*>(raw_ptr()->data_ + byte_offset);
5045 } 5051 }
5046 5052
(...skipping 29 matching lines...) Expand all
5076 return 0; 5082 return 0;
5077 } 5083 }
5078 5084
5079 static intptr_t InstanceSize(intptr_t lengthInBytes) { 5085 static intptr_t InstanceSize(intptr_t lengthInBytes) {
5080 ASSERT(0 <= lengthInBytes && lengthInBytes <= kSmiMax); 5086 ASSERT(0 <= lengthInBytes && lengthInBytes <= kSmiMax);
5081 return RoundedAllocationSize(sizeof(RawTypedData) + lengthInBytes); 5087 return RoundedAllocationSize(sizeof(RawTypedData) + lengthInBytes);
5082 } 5088 }
5083 5089
5084 static intptr_t ElementSizeInBytes(intptr_t class_id) { 5090 static intptr_t ElementSizeInBytes(intptr_t class_id) {
5085 ASSERT(RawObject::IsTypedDataClassId(class_id)); 5091 ASSERT(RawObject::IsTypedDataClassId(class_id));
5086 return element_size[class_id - kTypedDataInt8ArrayCid]; 5092 return element_size[ElementType(class_id)];
5093 }
5094
5095 static TypeDataElementType ElementType(intptr_t class_id) {
5096 ASSERT(RawObject::IsTypedDataClassId(class_id));
5097 return static_cast<TypeDataElementType>(
5098 class_id - kTypedDataInt8ArrayCid);
5087 } 5099 }
5088 5100
5089 static intptr_t MaxElements(intptr_t class_id) { 5101 static intptr_t MaxElements(intptr_t class_id) {
5090 ASSERT(RawObject::IsTypedDataClassId(class_id)); 5102 ASSERT(RawObject::IsTypedDataClassId(class_id));
5091 return (kSmiMax / ElementSizeInBytes(class_id)); 5103 return (kSmiMax / ElementSizeInBytes(class_id));
5092 } 5104 }
5093 5105
5094 static RawTypedData* New(intptr_t class_id, 5106 static RawTypedData* New(intptr_t class_id,
5095 intptr_t len, 5107 intptr_t len,
5096 Heap::Space space = Heap::kNew); 5108 Heap::Space space = Heap::kNew);
5097 5109
5098 static void Copy(const TypedData& dst, 5110 template <typename DstType, typename SrcType>
5099 intptr_t dst_offset_in_bytes, 5111 static void Copy(const DstType& dst, intptr_t dst_offset_in_bytes,
5100 const TypedData& src, 5112 const SrcType& src, intptr_t src_offset_in_bytes,
5101 intptr_t src_offset_in_bytes, 5113 intptr_t length_in_bytes) {
5102 intptr_t length_in_bytes); 5114 ASSERT(dst.ElementType() == src.ElementType());
5115 ASSERT(Utils::RangeCheck(src_offset_in_bytes,
5116 length_in_bytes,
5117 src.LengthInBytes()));
5118 ASSERT(Utils::RangeCheck(dst_offset_in_bytes,
5119 length_in_bytes,
5120 dst.LengthInBytes()));
5121 {
5122 NoGCScope no_gc;
5123 if (length_in_bytes > 0) {
5124 memmove(dst.DataAddr(dst_offset_in_bytes),
5125 src.DataAddr(src_offset_in_bytes),
5126 length_in_bytes);
5127 }
5128 }
5129 }
5103 5130
5104 static bool IsTypedData(const Instance& obj) { 5131 static bool IsTypedData(const Instance& obj) {
5105 ASSERT(!obj.IsNull()); 5132 ASSERT(!obj.IsNull());
5106 intptr_t cid = obj.raw()->GetClassId(); 5133 intptr_t cid = obj.raw()->GetClassId();
5107 return RawObject::IsTypedDataClassId(cid); 5134 return RawObject::IsTypedDataClassId(cid);
5108 } 5135 }
5109 5136
5110 protected: 5137 protected:
5111 void SetLength(intptr_t value) const { 5138 void SetLength(intptr_t value) const {
5112 raw_ptr()->length_ = Smi::New(value); 5139 raw_ptr()->length_ = Smi::New(value);
(...skipping 14 matching lines...) Expand all
5127 intptr_t Length() const { 5154 intptr_t Length() const {
5128 ASSERT(!IsNull()); 5155 ASSERT(!IsNull());
5129 return Smi::Value(raw_ptr()->length_); 5156 return Smi::Value(raw_ptr()->length_);
5130 } 5157 }
5131 5158
5132 intptr_t ElementSizeInBytes() const { 5159 intptr_t ElementSizeInBytes() const {
5133 intptr_t cid = raw()->GetClassId(); 5160 intptr_t cid = raw()->GetClassId();
5134 return ElementSizeInBytes(cid); 5161 return ElementSizeInBytes(cid);
5135 } 5162 }
5136 5163
5164 TypeDataElementType ElementType() const {
5165 intptr_t cid = raw()->GetClassId();
5166 return ElementType(cid);
5167 }
5168
5137 intptr_t LengthInBytes() const { 5169 intptr_t LengthInBytes() const {
5138 intptr_t cid = raw()->GetClassId(); 5170 intptr_t cid = raw()->GetClassId();
5139 return (ElementSizeInBytes(cid) * Length()); 5171 return (ElementSizeInBytes(cid) * Length());
5140 } 5172 }
5141 5173
5142 void* GetPeer() const { 5174 void* GetPeer() const {
5143 return raw_ptr()->peer_; 5175 return raw_ptr()->peer_;
5144 } 5176 }
5145 5177
5146 void* DataAddr(intptr_t byte_offset) const { 5178 void* DataAddr(intptr_t byte_offset) const {
(...skipping 30 matching lines...) Expand all
5177 static intptr_t data_offset() { 5209 static intptr_t data_offset() {
5178 return OFFSET_OF(RawExternalTypedData, data_); 5210 return OFFSET_OF(RawExternalTypedData, data_);
5179 } 5211 }
5180 5212
5181 static intptr_t InstanceSize() { 5213 static intptr_t InstanceSize() {
5182 return RoundedAllocationSize(sizeof(RawExternalTypedData)); 5214 return RoundedAllocationSize(sizeof(RawExternalTypedData));
5183 } 5215 }
5184 5216
5185 static intptr_t ElementSizeInBytes(intptr_t class_id) { 5217 static intptr_t ElementSizeInBytes(intptr_t class_id) {
5186 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); 5218 ASSERT(RawObject::IsExternalTypedDataClassId(class_id));
5187 return TypedData::element_size[class_id - kExternalTypedDataInt8ArrayCid]; 5219 return TypedData::element_size[ElementType(class_id)];
5220 }
5221
5222 static TypeDataElementType ElementType(intptr_t class_id) {
5223 ASSERT(RawObject::IsExternalTypedDataClassId(class_id));
5224 return static_cast<TypeDataElementType>(
5225 class_id - kExternalTypedDataInt8ArrayCid);
5188 } 5226 }
5189 5227
5190 static intptr_t MaxElements(intptr_t class_id) { 5228 static intptr_t MaxElements(intptr_t class_id) {
5191 ASSERT(RawObject::IsExternalTypedDataClassId(class_id)); 5229 ASSERT(RawObject::IsExternalTypedDataClassId(class_id));
5192 return (kSmiMax / ElementSizeInBytes(class_id)); 5230 return (kSmiMax / ElementSizeInBytes(class_id));
5193 } 5231 }
5194 5232
5195 static RawExternalTypedData* New(intptr_t class_id, 5233 static RawExternalTypedData* New(intptr_t class_id,
5196 uint8_t* data, 5234 uint8_t* data,
5197 intptr_t len, 5235 intptr_t len,
5198 Heap::Space space = Heap::kNew); 5236 Heap::Space space = Heap::kNew);
5199 5237
5200 static void Copy(const ExternalTypedData& dst,
5201 intptr_t dst_offset_in_bytes,
5202 const ExternalTypedData& src,
5203 intptr_t src_offset_in_bytes,
5204 intptr_t length_in_bytes);
5205
5206 static bool IsExternalTypedData(const Instance& obj) { 5238 static bool IsExternalTypedData(const Instance& obj) {
5207 ASSERT(!obj.IsNull()); 5239 ASSERT(!obj.IsNull());
5208 intptr_t cid = obj.raw()->GetClassId(); 5240 intptr_t cid = obj.raw()->GetClassId();
5209 return RawObject::IsExternalTypedDataClassId(cid); 5241 return RawObject::IsExternalTypedDataClassId(cid);
5210 } 5242 }
5211 5243
5212 protected: 5244 protected:
5213 void SetLength(intptr_t value) const { 5245 void SetLength(intptr_t value) const {
5214 raw_ptr()->length_ = Smi::New(value); 5246 raw_ptr()->length_ = Smi::New(value);
5215 } 5247 }
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
5656 5688
5657 5689
5658 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 5690 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
5659 intptr_t index) { 5691 intptr_t index) {
5660 return array.At((index * kEntryLength) + kTargetFunctionIndex); 5692 return array.At((index * kEntryLength) + kTargetFunctionIndex);
5661 } 5693 }
5662 5694
5663 } // namespace dart 5695 } // namespace dart
5664 5696
5665 #endif // VM_OBJECT_H_ 5697 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/lib/typeddata.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698