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

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

Issue 2908353002: Nonvirtual pointer visitor in GCs (Closed)
Patch Set: Separated user-defined classes case so it can be inlined Created 3 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
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 RUNTIME_VM_RAW_OBJECT_H_ 5 #ifndef RUNTIME_VM_RAW_OBJECT_H_
6 #define RUNTIME_VM_RAW_OBJECT_H_ 6 #define RUNTIME_VM_RAW_OBJECT_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/atomic.h" 9 #include "vm/atomic.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 return result; 446 return result;
447 } 447 }
448 448
449 bool Contains(uword addr) const { 449 bool Contains(uword addr) const {
450 intptr_t this_size = Size(); 450 intptr_t this_size = Size();
451 uword this_addr = RawObject::ToAddr(this); 451 uword this_addr = RawObject::ToAddr(this);
452 return (addr >= this_addr) && (addr < (this_addr + this_size)); 452 return (addr >= this_addr) && (addr < (this_addr + this_size));
453 } 453 }
454 454
455 void Validate(Isolate* isolate) const; 455 void Validate(Isolate* isolate) const;
456 intptr_t VisitPointers(ObjectPointerVisitor* visitor);
457 bool FindObject(FindObjectVisitor* visitor); 456 bool FindObject(FindObjectVisitor* visitor);
458 457
458 intptr_t VisitPointers(ObjectPointerVisitor* visitor) {
erikcorry 2017/05/31 10:40:42 I think instead of duplicating the code you can ju
459 // Fall back to virtual variant for predefined classes
460 intptr_t class_id = GetClassId();
461 if (class_id < kNumPredefinedCids) {
462 return VisitPointersPredefined(visitor, class_id);
463 }
464
465 // Calculate the first and last raw object pointer fields.
466 intptr_t instance_size = Size();
467 uword obj_addr = ToAddr(this);
468 uword from = obj_addr + sizeof(RawObject);
469 uword to = obj_addr + instance_size - kWordSize;
470
471 // Call visitor function non-virtually
472 visitor->VisitPointers(reinterpret_cast<RawObject**>(from),
473 reinterpret_cast<RawObject**>(to));
474
475 return instance_size;
476 }
477
478 template <class V>
erikcorry 2017/05/31 10:40:42 template <class V, bool call_virtually = false> T
479 intptr_t VisitPointersNonvirtual(V* visitor) {
erikcorry 2017/05/31 10:40:42 Perhaps it should be called VisitPointersTemplatiz
480 // Fall back to virtual variant for predefined classes
481 intptr_t class_id = GetClassId();
482 if (class_id < kNumPredefinedCids) {
483 return VisitPointersPredefined(visitor, class_id);
484 }
485
486 // Calculate the first and last raw object pointer fields.
487 intptr_t instance_size = Size();
488 uword obj_addr = ToAddr(this);
489 uword from = obj_addr + sizeof(RawObject);
490 uword to = obj_addr + instance_size - kWordSize;
491
492 // Call visitor function non-virtually
493 visitor->V::VisitPointers(reinterpret_cast<RawObject**>(from),
494 reinterpret_cast<RawObject**>(to));
495
496 return instance_size;
497 }
498
459 static RawObject* FromAddr(uword addr) { 499 static RawObject* FromAddr(uword addr) {
460 // We expect the untagged address here. 500 // We expect the untagged address here.
461 ASSERT((addr & kSmiTagMask) != kHeapObjectTag); 501 ASSERT((addr & kSmiTagMask) != kHeapObjectTag);
462 return reinterpret_cast<RawObject*>(addr + kHeapObjectTag); 502 return reinterpret_cast<RawObject*>(addr + kHeapObjectTag);
463 } 503 }
464 504
465 static uword ToAddr(const RawObject* raw_obj) { 505 static uword ToAddr(const RawObject* raw_obj) {
466 return reinterpret_cast<uword>(raw_obj->ptr()); 506 return reinterpret_cast<uword>(raw_obj->ptr());
467 } 507 }
468 508
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 class ReservedBits 546 class ReservedBits
507 : public BitField<uword, intptr_t, kReservedTagPos, kReservedTagSize> {}; 547 : public BitField<uword, intptr_t, kReservedTagPos, kReservedTagSize> {};
508 548
509 // TODO(koda): After handling tags_, return const*, like Object::raw_ptr(). 549 // TODO(koda): After handling tags_, return const*, like Object::raw_ptr().
510 RawObject* ptr() const { 550 RawObject* ptr() const {
511 ASSERT(IsHeapObject()); 551 ASSERT(IsHeapObject());
512 return reinterpret_cast<RawObject*>(reinterpret_cast<uword>(this) - 552 return reinterpret_cast<RawObject*>(reinterpret_cast<uword>(this) -
513 kHeapObjectTag); 553 kHeapObjectTag);
514 } 554 }
515 555
556 intptr_t VisitPointersPredefined(ObjectPointerVisitor* visitor,
557 intptr_t class_id);
558
516 intptr_t SizeFromClass() const; 559 intptr_t SizeFromClass() const;
517 560
518 intptr_t GetClassId() const { 561 intptr_t GetClassId() const {
519 uword tags = ptr()->tags_; 562 uword tags = ptr()->tags_;
520 return ClassIdTag::decode(tags); 563 return ClassIdTag::decode(tags);
521 } 564 }
522 565
523 void SetClassId(intptr_t new_cid) { 566 void SetClassId(intptr_t new_cid) {
524 uword tags = ptr()->tags_; 567 uword tags = ptr()->tags_;
525 ptr()->tags_ = ClassIdTag::update(new_cid, tags); 568 ptr()->tags_ = ClassIdTag::update(new_cid, tags);
(...skipping 1925 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 kTypedDataInt8ArrayViewCid + 15); 2494 kTypedDataInt8ArrayViewCid + 15);
2452 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14); 2495 COMPILE_ASSERT(kByteBufferCid == kExternalTypedDataInt8ArrayCid + 14);
2453 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1); 2496 COMPILE_ASSERT(kNullCid == kByteBufferCid + 1);
2454 return (kNullCid - kTypedDataInt8ArrayCid); 2497 return (kNullCid - kTypedDataInt8ArrayCid);
2455 } 2498 }
2456 2499
2457 2500
2458 } // namespace dart 2501 } // namespace dart
2459 2502
2460 #endif // RUNTIME_VM_RAW_OBJECT_H_ 2503 #endif // RUNTIME_VM_RAW_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698