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

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

Issue 10444091: Avoid reading RawObject::class_ directly in the runtime. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 30 matching lines...) Expand all
41 #endif 41 #endif
42 } 42 }
43 43
44 44
45 intptr_t RawObject::SizeFromClass() const { 45 intptr_t RawObject::SizeFromClass() const {
46 NoHandleScope no_handles(Isolate::Current()); 46 NoHandleScope no_handles(Isolate::Current());
47 47
48 // Only reasonable to be called on heap objects. 48 // Only reasonable to be called on heap objects.
49 ASSERT(IsHeapObject()); 49 ASSERT(IsHeapObject());
50 50
51 RawClass* raw_class = ptr()->class_; 51 // TODO(vegorov): this should be moved to fast path when class_ is eliminated.
52 if (FreeBit::decode(ptr()->tags_)) {
53 return reinterpret_cast<FreeListElement*>(ptr())->Size();
54 }
55
56 RawClass* raw_class = Isolate::Current()->class_table()->At(GetClassIndex());
52 intptr_t instance_size = raw_class->ptr()->instance_size_; 57 intptr_t instance_size = raw_class->ptr()->instance_size_;
53 ObjectKind instance_kind = raw_class->ptr()->instance_kind_; 58 ObjectKind instance_kind = raw_class->ptr()->instance_kind_;
54 59
55 if (instance_size == 0) { 60 if (instance_size == 0) {
56 switch (instance_kind) { 61 switch (instance_kind) {
57 case kTokenStream: { 62 case kTokenStream: {
58 const RawTokenStream* raw_tokens = 63 const RawTokenStream* raw_tokens =
59 reinterpret_cast<const RawTokenStream*>(this); 64 reinterpret_cast<const RawTokenStream*>(this);
60 intptr_t tokens_length = Smi::Value(raw_tokens->ptr()->length_); 65 intptr_t tokens_length = Smi::Value(raw_tokens->ptr()->length_);
61 instance_size = TokenStream::InstanceSize(tokens_length); 66 instance_size = TokenStream::InstanceSize(tokens_length);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 260 }
256 261
257 262
258 intptr_t RawObject::VisitPointers(ObjectPointerVisitor* visitor) { 263 intptr_t RawObject::VisitPointers(ObjectPointerVisitor* visitor) {
259 intptr_t size = 0; 264 intptr_t size = 0;
260 NoHandleScope no_handles(Isolate::Current()); 265 NoHandleScope no_handles(Isolate::Current());
261 266
262 // Only reasonable to be called on heap objects. 267 // Only reasonable to be called on heap objects.
263 ASSERT(IsHeapObject()); 268 ASSERT(IsHeapObject());
264 269
270 if (FreeBit::decode(ptr()->tags_)) {
271 // Nothing to visit for free list elements.
272 uword addr = RawObject::ToAddr(this);
273 FreeListElement* element = reinterpret_cast<FreeListElement*>(addr);
274 return element->Size();
275 }
276
265 // Read the necessary data out of the class before visting the class itself. 277 // Read the necessary data out of the class before visting the class itself.
266 RawClass* raw_class = ptr()->class_; 278 intptr_t class_index = GetClassIndex();
267 ObjectKind kind = raw_class->ptr()->instance_kind_; 279 ObjectKind kind;
280
281 if (class_index < kNumPredefinedKinds) {
282 kind = static_cast<ObjectKind>(class_index);
283 } else {
284 RawClass* raw_class = Isolate::Current()->class_table()->At(class_index);
285 kind = raw_class->ptr()->instance_kind_;
286 }
268 287
269 // Visit the class before visting the fields. 288 // Visit the class before visting the fields.
270 visitor->VisitPointer(reinterpret_cast<RawObject**>(&ptr()->class_)); 289 visitor->VisitPointer(reinterpret_cast<RawObject**>(&ptr()->class_));
271 290
272 switch (kind) { 291 switch (kind) {
273 #define RAW_VISITPOINTERS(clazz) \ 292 #define RAW_VISITPOINTERS(clazz) \
274 case clazz::kInstanceKind: { \ 293 case clazz::kInstanceKind: { \
275 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(this); \ 294 Raw##clazz* raw_obj = reinterpret_cast<Raw##clazz*>(this); \
276 size = Raw##clazz::Visit##clazz##Pointers(raw_obj, visitor); \ 295 size = Raw##clazz::Visit##clazz##Pointers(raw_obj, visitor); \
277 break; \ 296 break; \
278 } 297 }
279 CLASS_LIST_NO_OBJECT(RAW_VISITPOINTERS) 298 CLASS_LIST_NO_OBJECT(RAW_VISITPOINTERS)
280 #undef RAW_VISITPOINTERS 299 #undef RAW_VISITPOINTERS
281 case kFreeListElement: {
Ivan Posva 2012/05/31 13:06:24 You do not handle kFreeListElements here, but I do
Vyacheslav Egorov (Google) 2012/05/31 13:21:48 But free bit is always set for FreeListElement is
282 ASSERT(FreeBit::decode(ptr()->tags_));
283 // Nothing to visit for free list elements.
284 uword addr = RawObject::ToAddr(this);
285 FreeListElement* element = reinterpret_cast<FreeListElement*>(addr);
286 size = element->Size();
287 break;
288 }
289 default: 300 default:
290 OS::Print("Kind: %d\n", kind); 301 OS::Print("Kind: %d\n", kind);
291 UNREACHABLE(); 302 UNREACHABLE();
292 break; 303 break;
293 } 304 }
294 305
295 ASSERT(size != 0); 306 ASSERT(size != 0);
296 ASSERT(size == Size()); 307 ASSERT(size == Size());
297 return size; 308 return size;
298 } 309 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 443
433 intptr_t RawInstructions::VisitInstructionsPointers( 444 intptr_t RawInstructions::VisitInstructionsPointers(
434 RawInstructions* raw_obj, ObjectPointerVisitor* visitor) { 445 RawInstructions* raw_obj, ObjectPointerVisitor* visitor) {
435 RawInstructions* obj = raw_obj->ptr(); 446 RawInstructions* obj = raw_obj->ptr();
436 visitor->VisitPointer(reinterpret_cast<RawObject**>(&obj->code_)); 447 visitor->VisitPointer(reinterpret_cast<RawObject**>(&obj->code_));
437 return Instructions::InstanceSize(obj->size_); 448 return Instructions::InstanceSize(obj->size_);
438 } 449 }
439 450
440 451
441 bool RawInstructions::ContainsPC(RawObject* raw_obj, uword pc) { 452 bool RawInstructions::ContainsPC(RawObject* raw_obj, uword pc) {
442 RawClass* raw_class = raw_obj->ptr()->class_; 453 uword tags = raw_obj->ptr()->tags_;
443 ObjectKind instance_kind = raw_class->ptr()->instance_kind_; 454 if (RawObject::ClassTag::decode(tags) == kInstructions) {
444 if (instance_kind == kInstructions) {
445 RawInstructions* raw_instr = reinterpret_cast<RawInstructions*>(raw_obj); 455 RawInstructions* raw_instr = reinterpret_cast<RawInstructions*>(raw_obj);
446 uword start_pc = 456 uword start_pc =
447 reinterpret_cast<uword>(raw_instr->ptr()) + Instructions::HeaderSize(); 457 reinterpret_cast<uword>(raw_instr->ptr()) + Instructions::HeaderSize();
448 uword end_pc = start_pc + raw_instr->ptr()->size_; 458 uword end_pc = start_pc + raw_instr->ptr()->size_;
449 ASSERT(end_pc > start_pc); 459 ASSERT(end_pc > start_pc);
450 if ((pc >= start_pc) && (pc < end_pc)) { 460 if ((pc >= start_pc) && (pc < end_pc)) {
451 return true; 461 return true;
452 } 462 }
453 } 463 }
454 return false; 464 return false;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 RawUnwindError* raw_obj, ObjectPointerVisitor* visitor) { 567 RawUnwindError* raw_obj, ObjectPointerVisitor* visitor) {
558 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); 568 visitor->VisitPointers(raw_obj->from(), raw_obj->to());
559 return UnwindError::InstanceSize(); 569 return UnwindError::InstanceSize();
560 } 570 }
561 571
562 572
563 intptr_t RawInstance::VisitInstancePointers(RawInstance* raw_obj, 573 intptr_t RawInstance::VisitInstancePointers(RawInstance* raw_obj,
564 ObjectPointerVisitor* visitor) { 574 ObjectPointerVisitor* visitor) {
565 // Make sure that we got here with the tagged pointer as this. 575 // Make sure that we got here with the tagged pointer as this.
566 ASSERT(raw_obj->IsHeapObject()); 576 ASSERT(raw_obj->IsHeapObject());
567 RawInstance* obj = raw_obj->ptr(); 577 RawClass* cls = Isolate::Current()->class_table()->At(
568 intptr_t instance_size = obj->class_->ptr()->instance_size_; 578 raw_obj->GetClassIndex());
569 intptr_t num_native_fields = obj->class_->ptr()->num_native_fields_; 579 intptr_t instance_size = cls->ptr()->instance_size_;
580 intptr_t num_native_fields = cls->ptr()->num_native_fields_;
570 581
571 // Calculate the first and last raw object pointer fields. 582 // Calculate the first and last raw object pointer fields.
572 uword obj_addr = RawObject::ToAddr(raw_obj); 583 uword obj_addr = RawObject::ToAddr(raw_obj);
573 uword from = obj_addr + sizeof(RawObject) + num_native_fields * kWordSize; 584 uword from = obj_addr + sizeof(RawObject) + num_native_fields * kWordSize;
574 uword to = obj_addr + instance_size - kWordSize; 585 uword to = obj_addr + instance_size - kWordSize;
575 visitor->VisitPointers(reinterpret_cast<RawObject**>(from), 586 visitor->VisitPointers(reinterpret_cast<RawObject**>(from),
576 reinterpret_cast<RawObject**>(to)); 587 reinterpret_cast<RawObject**>(to));
577 return instance_size; 588 return instance_size;
578 } 589 }
579 590
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 intptr_t RawJSRegExp::VisitJSRegExpPointers(RawJSRegExp* raw_obj, 946 intptr_t RawJSRegExp::VisitJSRegExpPointers(RawJSRegExp* raw_obj,
936 ObjectPointerVisitor* visitor) { 947 ObjectPointerVisitor* visitor) {
937 // Make sure that we got here with the tagged pointer as this. 948 // Make sure that we got here with the tagged pointer as this.
938 ASSERT(raw_obj->IsHeapObject()); 949 ASSERT(raw_obj->IsHeapObject());
939 intptr_t length = Smi::Value(raw_obj->ptr()->data_length_); 950 intptr_t length = Smi::Value(raw_obj->ptr()->data_length_);
940 visitor->VisitPointers(raw_obj->from(), raw_obj->to()); 951 visitor->VisitPointers(raw_obj->from(), raw_obj->to());
941 return JSRegExp::InstanceSize(length); 952 return JSRegExp::InstanceSize(length);
942 } 953 }
943 954
944 } // namespace dart 955 } // 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