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

Side by Side Diff: runtime/vm/raw_object.cc

Issue 10538022: Do not reuse tags_ field to store next_ pointer of FreeListElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Allocate a real class for a free list element. Created 8 years, 6 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
« runtime/vm/raw_object.h ('K') | « runtime/vm/raw_object.h ('k') | no next file » | 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 #include "vm/raw_object.h" 5 #include "vm/raw_object.h"
6 6
7 #include "vm/class_table.h" 7 #include "vm/class_table.h"
8 #include "vm/freelist.h" 8 #include "vm/freelist.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
(...skipping 20 matching lines...) Expand all
31 #endif 31 #endif
32 } 32 }
33 33
34 34
35 intptr_t RawObject::SizeFromClass() const { 35 intptr_t RawObject::SizeFromClass() const {
36 NoHandleScope no_handles(Isolate::Current()); 36 NoHandleScope no_handles(Isolate::Current());
37 37
38 // Only reasonable to be called on heap objects. 38 // Only reasonable to be called on heap objects.
39 ASSERT(IsHeapObject()); 39 ASSERT(IsHeapObject());
40 40
41 // TODO(vegorov): this should be moved to fast path when class_ is eliminated.
42 if (FreeBit::decode(ptr()->tags_)) {
43 return reinterpret_cast<FreeListElement*>(ptr())->size();
44 }
45
46 RawClass* raw_class = Isolate::Current()->class_table()->At(GetClassId()); 41 RawClass* raw_class = Isolate::Current()->class_table()->At(GetClassId());
47 intptr_t instance_size = raw_class->ptr()->instance_size_; 42 intptr_t instance_size = raw_class->ptr()->instance_size_;
48 ObjectKind instance_kind = raw_class->ptr()->instance_kind_; 43 ObjectKind instance_kind = raw_class->ptr()->instance_kind_;
49 44
50 if (instance_size == 0) { 45 if (instance_size == 0) {
51 switch (instance_kind) { 46 switch (instance_kind) {
52 case kTokenStream: { 47 case kTokenStream: {
53 const RawTokenStream* raw_tokens = 48 const RawTokenStream* raw_tokens =
54 reinterpret_cast<const RawTokenStream*>(this); 49 reinterpret_cast<const RawTokenStream*>(this);
55 intptr_t tokens_length = Smi::Value(raw_tokens->ptr()->length_); 50 intptr_t tokens_length = Smi::Value(raw_tokens->ptr()->length_);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 const RawJSRegExp* raw_jsregexp = 221 const RawJSRegExp* raw_jsregexp =
227 reinterpret_cast<const RawJSRegExp*>(this); 222 reinterpret_cast<const RawJSRegExp*>(this);
228 intptr_t data_length = Smi::Value(raw_jsregexp->ptr()->data_length_); 223 intptr_t data_length = Smi::Value(raw_jsregexp->ptr()->data_length_);
229 instance_size = JSRegExp::InstanceSize(data_length); 224 instance_size = JSRegExp::InstanceSize(data_length);
230 break; 225 break;
231 } 226 }
232 case kFreeListElement: { 227 case kFreeListElement: {
233 ASSERT(FreeBit::decode(ptr()->tags_)); 228 ASSERT(FreeBit::decode(ptr()->tags_));
234 uword addr = RawObject::ToAddr(const_cast<RawObject*>(this)); 229 uword addr = RawObject::ToAddr(const_cast<RawObject*>(this));
235 FreeListElement* element = reinterpret_cast<FreeListElement*>(addr); 230 FreeListElement* element = reinterpret_cast<FreeListElement*>(addr);
236 instance_size = element->size(); 231 instance_size = element->Size();
237 break; 232 break;
238 } 233 }
239 default: 234 default:
240 UNREACHABLE(); 235 UNREACHABLE();
241 break; 236 break;
242 } 237 }
243 } 238 }
244 ASSERT(instance_size != 0); 239 ASSERT(instance_size != 0);
245 uword tags = ptr()->tags_; 240 uword tags = ptr()->tags_;
246 ASSERT((instance_size == SizeTag::decode(tags)) || 241 ASSERT((instance_size == SizeTag::decode(tags)) ||
247 (SizeTag::decode(tags) == 0) || 242 (SizeTag::decode(tags) == 0));
248 FreeBit::decode(tags));
249 return instance_size; 243 return instance_size;
250 } 244 }
251 245
252 246
253 intptr_t RawObject::VisitPointers(ObjectPointerVisitor* visitor) { 247 intptr_t RawObject::VisitPointers(ObjectPointerVisitor* visitor) {
254 intptr_t size = 0; 248 intptr_t size = 0;
255 NoHandleScope no_handles(visitor->isolate()); 249 NoHandleScope no_handles(visitor->isolate());
256 250
257 // Only reasonable to be called on heap objects. 251 // Only reasonable to be called on heap objects.
258 ASSERT(IsHeapObject()); 252 ASSERT(IsHeapObject());
259 253
260 if (FreeBit::decode(ptr()->tags_)) {
261 // Nothing to visit for free list elements.
262 uword addr = RawObject::ToAddr(this);
263 FreeListElement* element = reinterpret_cast<FreeListElement*>(addr);
264 return element->size();
265 }
266
267 // Read the necessary data out of the class before visting the class itself. 254 // Read the necessary data out of the class before visting the class itself.
268 intptr_t class_id = GetClassId(); 255 intptr_t class_id = GetClassId();
269 ObjectKind kind; 256 ObjectKind kind;
270 257
271 if (class_id < kNumPredefinedKinds) { 258 if (class_id < kNumPredefinedKinds) {
272 kind = static_cast<ObjectKind>(class_id); 259 kind = static_cast<ObjectKind>(class_id);
273 } else { 260 } else {
274 RawClass* raw_class = Isolate::Current()->class_table()->At(class_id); 261 RawClass* raw_class = Isolate::Current()->class_table()->At(class_id);
275 kind = raw_class->ptr()->instance_kind_; 262 kind = raw_class->ptr()->instance_kind_;
276 } 263 }
277 264
278 switch (kind) { 265 switch (kind) {
279 #define RAW_VISITPOINTERS(clazz) \ 266 #define RAW_VISITPOINTERS(clazz) \
280 case clazz::kInstanceKind: { \ 267 case clazz::kInstanceKind: { \
281 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(this); \ 268 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(this); \
282 size = Raw##clazz::Visit##clazz##Pointers(raw_obj, visitor); \ 269 size = Raw##clazz::Visit##clazz##Pointers(raw_obj, visitor); \
283 break; \ 270 break; \
284 } 271 }
285 CLASS_LIST_NO_OBJECT(RAW_VISITPOINTERS) 272 CLASS_LIST_NO_OBJECT(RAW_VISITPOINTERS)
286 #undef RAW_VISITPOINTERS 273 #undef RAW_VISITPOINTERS
274 case kFreeListElement: {
275 ASSERT(FreeBit::decode(ptr()->tags_));
276 uword addr = RawObject::ToAddr(const_cast<RawObject*>(this));
277 FreeListElement* element = reinterpret_cast<FreeListElement*>(addr);
278 size = element->Size();
279 break;
280 }
287 default: 281 default:
288 OS::Print("Kind: %d\n", kind); 282 OS::Print("Kind: %d\n", kind);
289 UNREACHABLE(); 283 UNREACHABLE();
290 break; 284 break;
291 } 285 }
292 286
293 ASSERT(size != 0); 287 ASSERT(size != 0);
294 ASSERT(size == Size()); 288 ASSERT(size == Size());
295 return size; 289 return size;
296 } 290 }
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 intptr_t RawJSRegExp::VisitJSRegExpPointers(RawJSRegExp* raw_obj, 927 intptr_t RawJSRegExp::VisitJSRegExpPointers(RawJSRegExp* raw_obj,
934 ObjectPointerVisitor* visitor) { 928 ObjectPointerVisitor* visitor) {
935 // Make sure that we got here with the tagged pointer as this. 929 // Make sure that we got here with the tagged pointer as this.
936 ASSERT(raw_obj->IsHeapObject()); 930 ASSERT(raw_obj->IsHeapObject());
937 intptr_t length = Smi::Value(raw_obj->ptr()->data_length_); 931 intptr_t length = Smi::Value(raw_obj->ptr()->data_length_);
938 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); 932 visitor->VisitPointers(raw_obj->from(), raw_obj->to());
939 return JSRegExp::InstanceSize(length); 933 return JSRegExp::InstanceSize(length);
940 } 934 }
941 935
942 } // namespace dart 936 } // namespace dart
OLDNEW
« runtime/vm/raw_object.h ('K') | « runtime/vm/raw_object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698